Changeset 76879 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Jan 18, 2019 10:17:25 AM (6 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvAudio.h
r76857 r76879 189 189 uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 190 190 uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 191 uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 191 192 uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 192 193 uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps); -
trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp
r76860 r76879 1238 1238 * @param cbBytes Amount of bytes to calculate time for. 1239 1239 * @param pProps PCM properties to calculate amount of bytes for. 1240 * 1241 * @note Does rounding up the result. 1240 1242 */ 1241 1243 uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps) … … 1243 1245 AssertPtrReturn(pProps, 0); 1244 1246 1245 if (!cbBytes) 1246 return 0; 1247 1248 const double dbBytesPerMs = (double)drvAudioHlpBytesPerSec(pProps) / (double)RT_MS_1SEC; 1249 Assert(dbBytesPerMs >= 0.0f); 1250 if (!dbBytesPerMs) /* Prevent division by zero. */ 1251 return 0; 1252 1253 return (double)cbBytes / (double)dbBytesPerMs; 1247 const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */); 1248 1249 uint64_t uTimeMs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_MS_1SEC; 1250 1251 return (uTimeMs + pProps->uHz - 1) / pProps->uHz; 1252 } 1253 1254 /** 1255 * Returns the time (in us) for given byte amount and PCM properties. 1256 * 1257 * @return uint64_t Calculated time (in us). 1258 * @param cbBytes Amount of bytes to calculate time for. 1259 * @param pProps PCM properties to calculate amount of bytes for. 1260 * 1261 * @note Does rounding up the result. 1262 */ 1263 uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps) 1264 { 1265 AssertPtrReturn(pProps, 0); 1266 1267 const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */); 1268 1269 uint64_t uTimeUs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_US_1SEC; 1270 1271 return (uTimeUs + pProps->uHz - 1) / pProps->uHz; 1254 1272 } 1255 1273 … … 1260 1278 * @param cbBytes Amount of bytes to calculate time for. 1261 1279 * @param pProps PCM properties to calculate amount of bytes for. 1280 * 1281 * @note Does rounding up the result. 1262 1282 */ 1263 1283 uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps) … … 1265 1285 AssertPtrReturn(pProps, 0); 1266 1286 1267 if (!cbBytes) 1268 return 0; 1269 1270 const double dbBytesPerMs = (PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */) * pProps->uHz) / RT_NS_1SEC; 1271 Assert(dbBytesPerMs >= 0.0f); 1272 if (!dbBytesPerMs) /* Prevent division by zero. */ 1273 return 0; 1274 1275 return cbBytes / dbBytesPerMs; 1287 const unsigned cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */); 1288 1289 uint64_t uTimeNs = ((cbBytes + cbFrame - 1) / cbFrame) * RT_NS_1SEC; 1290 1291 return (uTimeNs + pProps->uHz - 1) / pProps->uHz; 1276 1292 } 1277 1293
Note:
See TracChangeset
for help on using the changeset viewer.