Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
join wav files

drvds
Registered User
Quote
2013-09-15 17:05:48

Hello, I am trying to use irrklang to join two wav files, but I am kind of stuck right now. For the beginning I would like to just simply attach the data segment of one wav file to itself *to practice*.

For example: the input wav file might be 3 seconds long and someone says "ok", -> I want the output wavfile to be six second long with the person saying ok, twice - i hope this makes sense^^

I doubled the length and size, but something seems to be wrong with the way i duplicate the data buffer...



ISoundSource* firstwav = engine->addSoundSourceFromFile("somewav.wav");

SAudioStreamFormat format1 = firstwav->getAudioFormat();
SAudioStreamFormat format2 = secondwav->getAudioFormat();

// write wave header
unsigned short formatType = 1;
unsigned short numChannels = format1.ChannelCount;
unsigned long sampleRate = format1.SampleRate;
unsigned short bitsPerChannel = format1.getSampleSize() * 8;
unsigned short bytesPerSample = format1.getFrameSize() ;
unsigned long bytesPerSecond = format1.getBytesPerSecond();
unsigned long dataLen = format1.getSampleDataSize();

const int fmtChunkLen = 16;
const int waveHeaderLen = 4 + 8 + fmtChunkLen + 8;

unsigned long totalLen = waveHeaderLen + dataLen;

void* data = firstwav->getSampleData();

char* dopple = new char[dataLen*2];
char* single = (char*)data;

int counter1=0; int counter2 =0;
while(counter1 < dataLen )
{
dopple[counter1] = single[counter1];
counter1++;
}

//the error should be here
while(counter1 < dataLen)
{
dopple[counter1] = single[counter2];
counter1++;
counter2++;
}

dataLen = dataLen *2;
totalLen = waveHeaderLen + dataLen;

wxFile file1;
file1.Create("double.wav",true,wxS_DEFAULT);
if (!file1.IsOpened())
return false;
file1.Write("RIFF",4);
file1.Write(&totalLen, 4);
file1.Write("WAVE", 4);
file1.Write("fmt ", 4);
file1.Write(&fmtChunkLen, 4);
file1.Write(&formatType, 2);
file1.Write(&numChannels, 2);
file1.Write(&sampleRate, 4);
file1.Write(&bytesPerSecond, 4);
file1.Write(&bytesPerSample, 2);
file1.Write(&bitsPerChannel, 2);

// write data

file1.Write("data", 4);
file1.Write(&dataLen, 4);
file1.Write(dopple, dataLen);

file1.Close();




drvds
Registered User
Quote
2013-09-15 17:16:32

sorry about this post I figured it out myself. The second counter obviously has to check against dataLen * 2

while(counter1 < dataLen*2)
{
dopple[counter1] = single[counter2];
counter1++;
counter2++;
}



niko
Moderator
Quote
2013-09-16 21:41:48

Nice :)


drvds
Registered User
Quote
2013-09-17 11:24:39

thx :)

on a similar note, I have change the method now so it can now
eiterh join two wav files, or join two wave files with a user-specified intervall in the middle - however... there are sound artifacts at the end of my first wav / at the beginning of the intervall wav.

Apparently this is quite normal and the way around it would be to fade out at the end of wav 1 and fade back in at the beginning of wav 2. / the dummy intervall wav.

Also see: http://www.ambiera.com/forum.php?t=307

The only problem now is that my wav files are already recorded so I basically need to change the volume in the data segment in the recorded wav file... is there any way to access this data with irrklang ?
and then change the volume of say the last 0.5 seconds ?


drvds
Registered User
Quote
2013-09-17 18:02:36

SelbstgesprÃĪche...

In case someone needs it in the future - the trick with the audio artifacts was to use memset on the allocated buffers before filling them with other stuff .

This part of the function below should get anyone on the right track that wants to add a buffer-wav of x-length to their preexisting wav.

Great API ! by the way


// that here is the formular to compute the length of the data segment in the buffer wav
unsigned long dataLen2 = format1.SampleRate * format1.ChannelCount * format1.getSampleSize() * seconds;
char* emptybuf = new char[dataLen2];

// lets create a bigbuffer, so we can attach the seconddatabuffer to the first.

char* bigbuffer = new char[dataLen1+dataLen2]; //sizeof(emptybuf)];
// prevents audio artifacts !! - very important
memset(bigbuffer,0,dataLen1+dataLen2);
memset(emptybuf,0,dataLen2);

char* firstbuffer = (char*)data1;
char* secondbuffer = emptybuf;

int counter1=0; int counter2 =0;

while(counter1 < dataLen1 )
{
bigbuffer[counter1] = firstbuffer[counter1]; // * x increases volume
counter1++;

}
while(counter1 < dataLen1+dataLen2)
{
bigbuffer[counter1] = secondbuffer[counter2];
counter1++;
counter2++;
}

dataLen2 = dataLen1+dataLen2;
totalLen1 = waveHeaderLen1 + dataLen2;


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact