@@ -1156,7 +1156,7 @@ int AudioOutputBase::CheckFreeSpace(int &frames)
1156
1156
* Returns the number of frames written, which may be less than requested
1157
1157
* if the upmixer buffered some (or all) of them
1158
1158
*/
1159
- int AudioOutputBase::CopyWithUpmix (char *buffer, int frames, int &org_waud)
1159
+ int AudioOutputBase::CopyWithUpmix (char *buffer, int frames, uint &org_waud)
1160
1160
{
1161
1161
int len = CheckFreeSpace (frames);
1162
1162
int bdiff = kAudioRingBufferSize - org_waud;
@@ -1176,7 +1176,7 @@ int AudioOutputBase::CopyWithUpmix(char *buffer, int frames, int &org_waud)
1176
1176
}
1177
1177
if (num > 0 )
1178
1178
memcpy (WPOS, buffer + off, num);
1179
- org_waud += num;
1179
+ org_waud = (org_waud + num) % kAudioRingBufferSize ;
1180
1180
return len;
1181
1181
}
1182
1182
@@ -1194,7 +1194,7 @@ int AudioOutputBase::CopyWithUpmix(char *buffer, int frames, int &org_waud)
1194
1194
if (frames > 0 )
1195
1195
AudioOutputUtil::MonoToStereo (WPOS, buffer + off, frames);
1196
1196
1197
- org_waud += frames * bpf;
1197
+ org_waud = (org_waud + frames * bpf) % kAudioRingBufferSize ;
1198
1198
return len;
1199
1199
}
1200
1200
@@ -1225,7 +1225,7 @@ int AudioOutputBase::CopyWithUpmix(char *buffer, int frames, int &org_waud)
1225
1225
if (nFrames > 0 )
1226
1226
upmixer->receiveFrames ((float *)(WPOS), nFrames);
1227
1227
1228
- org_waud += nFrames * bpf;
1228
+ org_waud = (org_waud + nFrames * bpf) % kAudioRingBufferSize ;
1229
1229
}
1230
1230
return len;
1231
1231
}
@@ -1276,9 +1276,9 @@ bool AudioOutputBase::AddData(void *in_buffer, int in_len,
1276
1276
// Don't write new samples if we're resetting the buffer or reconfiguring
1277
1277
QMutexLocker lock (&audio_buflock);
1278
1278
1279
- int org_waud = waud;
1280
- int afree = audiofree ();
1281
- int used = kAudioRingBufferSize - afree;
1279
+ uint org_waud = waud;
1280
+ int afree = audiofree ();
1281
+ int used = kAudioRingBufferSize - afree;
1282
1282
1283
1283
if (passthru && m_spdifenc)
1284
1284
{
@@ -1336,13 +1336,16 @@ bool AudioOutputBase::AddData(void *in_buffer, int in_len,
1336
1336
AudioOutputSettings::SampleSize (format) * len;
1337
1337
1338
1338
// Account for changes in number of channels
1339
- if (needs_upmix || needs_downmix)
1340
- len = (len / source_channels) * configured_channels ;
1339
+ if (needs_downmix)
1340
+ len = (len * configured_channels ) / source_channels ;
1341
1341
1342
1342
// Check we have enough space to write the data
1343
1343
if (need_resampler && src_ctx)
1344
1344
len = (int )ceilf (float (len) * src_data.src_ratio );
1345
1345
1346
+ if (needs_upmix)
1347
+ len = (len * configured_channels ) / source_channels;
1348
+
1346
1349
// Include samples in upmix buffer that may be flushed
1347
1350
if (needs_upmix && upmixer)
1348
1351
len += upmixer->numUnprocessedFrames () * bpf;
@@ -1452,7 +1455,7 @@ bool AudioOutputBase::AddData(void *in_buffer, int in_len,
1452
1455
nFrames = pSoundStretch->receiveSamples ((STST *)(WPOS),
1453
1456
nFrames);
1454
1457
1455
- org_waud += nFrames * bpf;
1458
+ org_waud = (org_waud + nFrames * bpf) % kAudioRingBufferSize ;
1456
1459
}
1457
1460
1458
1461
if (internal_vol && SWVolume ())
@@ -1470,7 +1473,7 @@ bool AudioOutputBase::AddData(void *in_buffer, int in_len,
1470
1473
if (num > 0 )
1471
1474
AudioOutputUtil::AdjustVolume (WPOS, num, volume,
1472
1475
music, needs_upmix && upmixer);
1473
- org_waud += num;
1476
+ org_waud = (org_waud + num) % kAudioRingBufferSize ;
1474
1477
}
1475
1478
1476
1479
if (encoder)
@@ -1499,7 +1502,7 @@ bool AudioOutputBase::AddData(void *in_buffer, int in_len,
1499
1502
if (to_get > 0 )
1500
1503
encoder->GetFrames (WPOS, to_get);
1501
1504
1502
- org_waud += to_get;
1505
+ org_waud = (org_waud + to_get) % kAudioRingBufferSize ;
1503
1506
}
1504
1507
1505
1508
waud = org_waud;
@@ -1612,7 +1615,7 @@ void AudioOutputBase::OutputAudioLoop(void)
1612
1615
// delay setting raud until after phys buffer is filled
1613
1616
// so GetAudiotime will be accurate without locking
1614
1617
reset_active.TestAndDeref ();
1615
- int next_raud = raud;
1618
+ volatile uint next_raud = raud;
1616
1619
if (GetAudioData (fragment, fragment_size, true , &next_raud))
1617
1620
{
1618
1621
if (!reset_active.TestAndDeref ())
@@ -1644,7 +1647,7 @@ void AudioOutputBase::OutputAudioLoop(void)
1644
1647
* available. Returns the number of bytes copied.
1645
1648
*/
1646
1649
int AudioOutputBase::GetAudioData (uchar *buffer, int size, bool full_buffer,
1647
- int *local_raud)
1650
+ volatile uint *local_raud)
1648
1651
{
1649
1652
1650
1653
#define LRPOS audiobuffer + *local_raud
@@ -1743,5 +1746,3 @@ int AudioOutputBase::readOutputData(unsigned char*, int)
1743
1746
VBERROR (" AudioOutputBase should not be getting asked to readOutputData()" );
1744
1747
return 0 ;
1745
1748
}
1746
-
1747
-
0 commit comments