Exemple #1
0
 public Uart2Sound(WavConfig config, int baud)
 {
     this.stream          = new WavStream();
     this.config          = config;
     config.samplesPerBit = (this.config.sampleRate / 1000.0) * (1000.0 / baud);
     Amplitude            = 40000;
 }
Exemple #2
0
 public void writeSample(uint sample, WavConfig config)
 {
     if (config.bitsPerSample == WavConfig.BPS_16BIT)
     {
         writeInt16((ushort)sample);
         dataLen += 2;
     }
     else if (config.bitsPerSample == WavConfig.BPS_8BIT)
     {
         write8bit((byte)sample);
         dataLen += 1;
     }
 }
Exemple #3
0
        public void WriteHeader(WavConfig config)
        {
            var blockAlign = config.channels * (config.bitsPerSample / 8);

            stream.writeTag(System.Text.Encoding.UTF8.GetBytes(WavConfig.tagRiff));
            stream.writeInt32(0);
            stream.writeTag(System.Text.Encoding.UTF8.GetBytes(WavConfig.tagWave));
            stream.writeTag(System.Text.Encoding.UTF8.GetBytes(WavConfig.tagFmt));
            stream.writeInt32(16);
            stream.writeInt16(WavConfig.LIBWAV_FORMAT_PCM);
            stream.writeInt16(config.channels);
            stream.writeInt32((int)config.sampleRate);
            stream.writeInt32((int)(config.sampleRate * blockAlign));
            stream.writeInt16((ushort)blockAlign);
            stream.writeInt16(config.bitsPerSample);
            stream.writeTag(System.Text.Encoding.UTF8.GetBytes(WavConfig.tagData));
            dataOffset = (int)stream.Stream.Position;
            stream.writeInt32(0);
        }