- Timestamp:
- Jul 31, 2018 11:25:00 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 124025
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvAudio.h
r73381 r73407 188 188 uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 189 189 uint64_t DrvAudioHlpBytesToMs(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 190 uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps); 190 191 uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps); 191 192 uint64_t DrvAudioHlpFramesToMs(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps); 193 uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps); 192 194 uint32_t DrvAudioHlpMsToBytes(uint32_t uMs, const PPDMAUDIOPCMPROPS pProps); 195 uint32_t DrvAudioHlpNanoToBytes(uint32_t uNs, const PPDMAUDIOPCMPROPS pProps); 193 196 uint32_t DrvAudioHlpMsToFrames(uint32_t uMs, const PPDMAUDIOPCMPROPS pProps); 197 uint32_t DrvAudioHlpNanoToFrames(uint32_t uNs, const PPDMAUDIOPCMPROPS pProps); 194 198 /** @} */ 195 199 -
trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp
r73381 r73407 1136 1136 1137 1137 /** 1138 * Returns the time (in ns) for given byte amount and PCM properties. 1139 * 1140 * @return uint64_t Calculated time (in ns). 1141 * @param cbBytes Amount of bytes to calculate time for. 1142 * @param pProps PCM properties to calculate amount of bytes for. 1143 */ 1144 uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps) 1145 { 1146 AssertPtrReturn(pProps, 0); 1147 1148 if (!cbBytes) 1149 return 0; 1150 1151 const float dbBytesPerMs = ((pProps->cBits / 8) * pProps->cChannels * pProps->uHz) / RT_NS_1SEC; 1152 Assert(dbBytesPerMs >= 0.0f); 1153 if (!dbBytesPerMs) /* Prevent division by zero. */ 1154 return 0; 1155 1156 return cbBytes / dbBytesPerMs; 1157 } 1158 1159 /** 1138 1160 * Returns the bytes for a given audio frames amount and PCM properties. 1139 1161 * … … 1173 1195 1174 1196 /** 1197 * Returns the time (in ns) for given audio frames amount and PCM properties. 1198 * 1199 * @return uint64_t Calculated time (in ns). 1200 * @param cFrames Amount of audio frames to calculate time for. 1201 * @param pProps PCM properties to calculate time (in ns) for. 1202 */ 1203 uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps) 1204 { 1205 AssertPtrReturn(pProps, 0); 1206 1207 if (!cFrames) 1208 return 0; 1209 1210 if (!pProps->uHz) /* Prevent division by zero. */ 1211 return 0; 1212 1213 return cFrames / float(pProps->uHz / RT_NS_1SEC); 1214 } 1215 1216 /** 1175 1217 * Returns the amount of bytes for a given time (in ms) and PCM properties. 1176 1218 * … … 1190 1232 1191 1233 /** 1192 * Returns the amount of audio for a given time (in ms) and PCM properties. 1234 * Returns the amount of bytes for a given time (in ns) and PCM properties. 1235 * 1236 * @return uint32_t Calculated amount of bytes. 1237 * @param uNs Time (in ns) to calculate amount of bytes for. 1238 * @param pProps PCM properties to calculate amount of bytes for. 1239 */ 1240 uint32_t DrvAudioHlpNanoToBytes(uint32_t uNs, const PPDMAUDIOPCMPROPS pProps) 1241 { 1242 AssertPtrReturn(pProps, 0); 1243 1244 if (!uNs) 1245 return 0; 1246 1247 return float(((pProps->cBits / 8) * pProps->cChannels * pProps->uHz) / RT_NS_1SEC) * uNs; 1248 } 1249 1250 /** 1251 * Returns the amount of audio frames for a given time (in ms) and PCM properties. 1193 1252 * 1194 1253 * @return uint32_t Calculated amount of audio frames. 1195 * @param uMs Time (in ms) to calculate amount of bytes for.1196 * @param pProps PCM properties to calculate amount of bytes for.1254 * @param uMs Time (in ms) to calculate amount of frames for. 1255 * @param pProps PCM properties to calculate amount of frames for. 1197 1256 */ 1198 1257 uint32_t DrvAudioHlpMsToFrames(uint32_t uMs, const PPDMAUDIOPCMPROPS pProps) … … 1205 1264 1206 1265 return DrvAudioHlpMsToBytes(uMs, pProps) / cbFrame; 1266 } 1267 1268 /** 1269 * Returns the amount of audio frames for a given time (in ns) and PCM properties. 1270 * 1271 * @return uint32_t Calculated amount of audio frames. 1272 * @param uNs Time (in ns) to calculate amount of frames for. 1273 * @param pProps PCM properties to calculate amount of frames for. 1274 */ 1275 uint32_t DrvAudioHlpNanoToFrames(uint32_t uNs, const PPDMAUDIOPCMPROPS pProps) 1276 { 1277 AssertPtrReturn(pProps, 0); 1278 1279 const uint32_t cbFrame = (pProps->cBits / 8) * pProps->cChannels; 1280 if (!cbFrame) /* Prevent division by zero. */ 1281 return 0; 1282 1283 return DrvAudioHlpNanoToBytes(uNs, pProps) / cbFrame; 1207 1284 } 1208 1285
Note:
See TracChangeset
for help on using the changeset viewer.