0
0

Hi all,

I’ve been working on making an output file with multichannel outputs.

By combining recording and recordtodisk examples,

my code could play multichannel sounds and record from my mic input.

But what I want to do is recording multichannel sounds that I’m playing and to create an wav file with it.

In short, I want to make an wav file from my multichannel outputs.

Can anyone give me some hint or tell me what to do?

Thanks in advance!

[code:2ki2j5kv]
if (kbhit())
{
key = getch();

        switch (key)
        {
            case '0':
            {
                result = pSystem[0]->playSound(FMOD_CHANNEL_FREE, pSound[0], false, &pChannel[0]);
                ERRCHECK(result);
                break;
            }
            case '1':
            {
                result = pSystem[1]->playSound(FMOD_CHANNEL_FREE, pSound[1], false, &pChannel[1]);
                ERRCHECK(result);
                break;
            }

            case '2':
            {
                result = pSystem[2]->playSound(FMOD_CHANNEL_FREE, pSound[2], false, &pChannel[2]);
                ERRCHECK(result);
                break;
            }

            case '3':
            {
                result = pSystem[3]->playSound(FMOD_CHANNEL_FREE, pSound[3], false, &pChannel[3]);
                ERRCHECK(result);
                break;
            }

            case '4':
            {
                result = pSystem[4]->playSound(FMOD_CHANNEL_FREE, pSound[4], false, &pChannel[4]);
                ERRCHECK(result);
                break;
            }

            case 'r' :
            case 'R' :
            {
                result = system->recordStart(recorddriver, sound, looping);
                ERRCHECK(result);
                break;
            }
            case 'p' :
            case 'P' :
            {
                if (looping)
                {
                    sound->setMode(FMOD_LOOP_NORMAL);
                }
                else
                {
                    sound->setMode(FMOD_LOOP_OFF);
                }
                ERRCHECK(result);

                result = system->playSound(FMOD_CHANNEL_REUSE, sound, false, &channel);
                ERRCHECK(result);

                break;
            }
            case 'l' :
            case 'L' :
            {
                looping = !looping;
                break;
            }
            case 's' :
            case 'S' :
            {
                result = system->recordStop(recorddriver);
                if (channel)
                {
                    channel->stop();
                    channel = 0;
                }
                break;
            }
            case 'w' :
            case 'W' :
            {
                printf("Writing to record.wav ...                                                     \r");

                SaveToWav(sound);

                Sleep(500);
                break;
            }
        }
    }

[/code:2ki2j5kv]

  • You must to post comments
0
0

Hi zechery, welcome to the forums.

It sounds like you’re aiming to take many mono/stereo sound files and interleave them into a multichannel sound file. If that is the case then you shouldn’t play the sounds and you don’t need to record either. Playing sounds will cause them to get mixed together. And the recording API is only useful for microphones.

To create a mutlichannel file you need to get the raw PCM data from the FMOD::Sound objects and interleave that into a single buffer then write that to file.

-Pete

  • You must to post comments
0
0

Hi Peter, thanks for your reply.

I fixed my problem by enabling stereo mix on recording settings.

So now I can make a wav file with what I hear!! :)

For the next step, is there a way to encode wav file to mp3 file?

Should I convert into mp3 after makeing a wav file or is there a way to get mp3 file right after recording?

  • Zec
  • You must to post comments
0
0

I don’t entirely understand what you’re trying to achieve. I think there is some confusion arising from the word ‘channel’. I think your comment about multichannel output threw me a little.

Now that I reread your post, it sounds more like you want to mix sounds together and just record the output. For this you can use either the wavewriter output mode, or create a custom dsp you capture the audio and write it to a file.

  • You must to post comments
0
0

wow, you wrote a replay while i was editing my one!

thanks for the reply again, and yes, I have wanted to get mix sounds together.

could you answer me for the next step? :)

  • You must to post comments
0
0

Ok, to mix them together you need to get the raw PCM data that is going through the FMOD mixer. To do this you need to create a custom dsp unit and attach it to your FMOD system object.

[Note: I’m just going to assume you want to make a 16-bit wav file, there are other types but 16-bit is the most common]

The custom DSP object needs to do the following things:
* convert the 32-bit float PCM data in the mixer to 16-bit short data for a wav file.
* write that data to the file.

To make a .wav file you need more than just data though, you also need a header. There is one thing that makes recording realtime data as a wav file a bit tricky: You have to write the header at the start of the file, [i:9yhzg775]but [/i:9yhzg775]the header has to contain the length of the sound. Well the length of the sound is unknown at the start since it’s recording in realtime, so that what makes it tricky. The solution is to write a empty header to the file, then follow that with your 16-bit sound data. When you have finished recording then you know the length of the sound so you can write a real header on top of the empty header and thats it!

There is an example of how to write a wav file header in the recordtodisk example. That example get it’s data from the microphone, whereas for your application you need to get you data from the mixer, so there is a lot of code in that example which is not relevant here. Take a look at how that example writes the header, then writes data, and then later writes the header again.

-Pete

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.