0
0

Hey all,

I’m working on an app that records sound from the line input for 10 seconds every 2 minutes, and then saves it to a memory card. It works fine, but after about 3-4 days of running, it fails to initialize or start recording. I’m fairly new at C#, so could someone take a look at the code below and give any suggestions. Before anyone asks why I leave it running for so long, it is for data collection, and I’m hoping it can run for 12 days with a 8Gb CF card.

This is using the C# wrapper for FMOD.

[code:ch4b2mng] private IntPtr AudioSampleStart()
{
CSound m_RecordSample = new CSound();

        recordingWAV = true;
        string m_FileName;
        using (StreamWriter error = new StreamWriter(destDrive + "\\" + "error.log", true))
        {

            m_FileName = destDrive + "\\" + timestamped + ".wav";

            if (!FMOD.System.Init(44100, 16))
            {
                error.WriteLine("FMOD failed to initialize for sample " + m_FileName);
            }

            m_RecordSample.m_pData = FMOD.Sound.Sample.Alloc(0, recLength, FMOD.Sound.FSOUND_NORMAL, sampleRate, 255);

            if (!FMOD.Sound.Recorder.StartRecording(m_RecordSample.m_pData, false))
            {
                error.WriteLine("FMOD failed to start recording for sample " + m_FileName);
            }
        }

        audioFileName = m_FileName;

        return m_RecordSample.m_pData;
    }


    private void AudioSampleStop(string wavFileName, IntPtr wavData)
    {
        if (!FMOD.Sound.Recorder.SaveToPCM(wavData, wavFileName))
        {
        }

        //Free allocated memory

        FMOD.System.ReleaseAllFileHandles();
        FMOD.Sound.Sample.Free(wavData);
        FMOD.System.Close();

        recordingWAV = false;
    }

wavData = AudioSampleStart();

//code to wait 2 minutes, and do other commands

AudioSampleStop(audioFileName, wavData);

[/code:ch4b2mng]

  • You must to post comments
0
0

Hi there… one thing I would suggest trying is only initialise FMOD once when the application starts.

I have not used the recording routines myself, but from this point of view I would assume that it is the same as the playback… the library only needs to be initialised once.

And although you are performing the close, this could be the reason why it refuses to initialise (or start recording… you didn’t say which).

Also I would recommend seeing what the error code is.

Cheers
Ronny

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.