Author Topic: Add second of Silence to _recBuffer beginning  (Read 339 times)

cablehead

  • Posts: 315
Winstore-

I am using silence detection(ChannelGetData) in my recproc to avoid writing massive silent .wavs. It works great..maybe too good. Is there anyway I can add a second of silence to the beginning of the sample before writing?

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Add second of Silence to _recBuffer beginning
« Reply #1 on: 16 Feb '17 - 17:46 »
If I recall correctly, you're using your own file writing code? If so, you could just write a block of 0s at the start. You can use BASS_ChannelSeconds2Bytes (on the recording handle) to get the number of 0s to write.

cablehead

  • Posts: 315
Re: Add second of Silence to _recBuffer beginning
« Reply #2 on: 16 Feb '17 - 18:34 »
Dont really understand Channel2Bytes...? Yes my own writer.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Add second of Silence to _recBuffer beginning
« Reply #3 on: 17 Feb '17 - 17:05 »
BASS_ChannelSeconds2Bytes will translate a number of seconds to a number of bytes, based on the BASS channel's sample format. In this case, you want to translate 1 second:

Code: [Select]
long bytes = BASS_ChannelSeconds2Bytes(rechandle, 1);
// write "bytes" number of 0s to the WAV file...

cablehead

  • Posts: 315
Re: Add second of Silence to _recBuffer beginning
« Reply #4 on: 18 Feb '17 - 14:40 »
 public void Write(byte[] buffer, int bytesRecorded)
        {
            try
            {
                if (firstSample)
                {
                    firstSample = false;
                    long silence = Bass.BASS_ChannelSeconds2Bytes(recordHandle, 1);
                    byte[] mybyt = BitConverter.GetBytes(silence);
                    _fileStream.Write(mybyt, 0, mybyt.Length);
                    _dataChunkSize += mybyt.Length;
                   
                }
                _fileStream.Write(buffer, 0, bytesRecorded);
                _dataChunkSize += bytesRecorded;

            }
            catch { }
        }

Its not adding silence to beginning....?

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Add second of Silence to _recBuffer beginning
« Reply #5 on: 20 Feb '17 - 15:44 »
                    byte[] mybyt = BitConverter.GetBytes(silence);

I'm not a .Net user, but I believe that call will only give you a 4 byte array. Try this instead:

Code: [Select]
                    byte[] mybyt = new byte[silence];

cablehead

  • Posts: 315
Re: Add second of Silence to _recBuffer beginning
« Reply #6 on: 13 Mar '17 - 16:18 »
Still having trouble with this. Does ChannelSeconds2Bytes add the zero's just by calling it? I Just need to add a second of silence before the first sample hits the recproc...

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: Add second of Silence to _recBuffer beginning
« Reply #7 on: 13 Mar '17 - 16:24 »
No, BASS_ChannelSeconds2Bytes won't add the 0s itself. It just tells you how many 0s you need.