@@ -88,7 +88,7 @@ uint32_t DLSFile::GetSize(void) {
8888}
8989
9090
91- int DLSFile::WriteDLSToBuffer (vector<uint8_t > &buf) {
91+ int DLSFile::WriteDLSToBuffer (vector<uint8_t > &buf, bool mono ) {
9292 uint32_t theDWORD;
9393
9494 PushTypeOnVectBE<uint32_t >(buf, 0x52494646 ); // "RIFF"
@@ -123,7 +123,7 @@ int DLSFile::WriteDLSToBuffer(vector<uint8_t> &buf) {
123123 theDWORD += aWaves[i]->GetSize (); // each "wave" list
124124 WriteLIST (buf, 0x7776706C , theDWORD); // Write the "wvpl" LIST
125125 for (uint32_t i = 0 ; i < aWaves.size (); i++)
126- aWaves[i]->Write (buf); // Write each "wave" list
126+ aWaves[i]->Write (buf, mono); // Write each "wave" list
127127
128128 theDWORD = 12 + (uint32_t ) name.size (); // "INFO" + "INAM" + size + the string size
129129 WriteLIST (buf, 0x494E464F , theDWORD); // write the "INFO" list
@@ -463,14 +463,39 @@ uint32_t DLSWave::GetSize() {
463463 return size;
464464}
465465
466- void DLSWave::Write (vector<uint8_t > &buf) {
466+ void DLSWave::GetChannelData (vector<uint8_t > &buf, uint8_t whichChannel) {
467+ uint32_t chSize = dataSize / wChannels;
468+ PushTypeOnVect<uint32_t >(buf, chSize);
469+
470+ uint8_t bytesPerSample = wBitsPerSample / 8 ;
471+ uint8_t skip = wChannels * bytesPerSample;
472+ for (uint32_t i = whichChannel * bytesPerSample; i < dataSize; i += skip) {
473+ buf.insert (buf.end (), &data[i], &data[i + bytesPerSample]);
474+ }
475+ }
476+
477+ void DLSWave::WriteSample (vector<uint8_t > &buf, bool mono) {
478+ if (false && (wChannels != 1 && mono)) {
479+ // Just get the left sample.
480+ GetChannelData (buf, 0 );
481+ } else {
482+ PushTypeOnVect<uint32_t >(buf, dataSize); // size: this is the ACTUAL size, not the even-aligned size
483+ if (dataSize % 2 )
484+ buf.push_back (0 );
485+ buf.insert (buf.end (), data, data + dataSize); // Write the sample
486+ }
487+ }
488+
489+ void DLSWave::Write (vector<uint8_t > &buf, bool mono) {
490+ mono = false ;
467491 uint32_t theDWORD;
492+ uint16_t numChannels = mono ? 1 : wChannels;
468493
469494 RiffFile::WriteLIST (buf, 0x77617665 , GetSize () - 8 ); // write "wave" list
470495 PushTypeOnVectBE<uint32_t >(buf, 0x666D7420 ); // "fmt "
471496 PushTypeOnVect<uint32_t >(buf, 18 ); // size
472497 PushTypeOnVect<uint16_t >(buf, wFormatTag); // wFormatTag
473- PushTypeOnVect<uint16_t >(buf, wChannels); // wChannels
498+ PushTypeOnVect<uint16_t >(buf, numChannels); // wChannels
474499 PushTypeOnVect<uint32_t >(buf, dwSamplesPerSec); // dwSamplesPerSec
475500 PushTypeOnVect<uint32_t >(buf, dwAveBytesPerSec); // dwAveBytesPerSec
476501 PushTypeOnVect<uint16_t >(buf, wBlockAlign); // wBlockAlign
@@ -482,10 +507,7 @@ void DLSWave::Write(vector<uint8_t> &buf) {
482507 Wsmp->Write (buf); // write the "wsmp" chunk
483508
484509 PushTypeOnVectBE<uint32_t >(buf, 0x64617461 ); // "data"
485- PushTypeOnVect<uint32_t >(buf, dataSize); // size: this is the ACTUAL size, not the even-aligned size
486- buf.insert (buf.end (), data, data + dataSize); // Write the sample
487- if (dataSize % 2 )
488- buf.push_back (0 );
510+ WriteSample (buf, mono);
489511 theDWORD = 12 + (uint32_t ) name.size (); // "INFO" + "INAM" + size + the string size
490512 RiffFile::WriteLIST (buf, 0x494E464F , theDWORD); // write the "INFO" list
491513 PushTypeOnVectBE<uint32_t >(buf, 0x494E414D ); // "INAM"
0 commit comments