Пример #1
0
        private void DecodeFormat(int format, out MiniFormatTag codec, out int channels, out int rate, out int alignment)
        {
            if (_version == 1)
            {
                // I'm not 100% sure if the following is correct
                // version 1:
                // 1 00000000 000101011000100010 0 001 0
                // | |         |                 | |   |
                // | |         |                 | |   wFormatTag
                // | |         |                 | nChannels
                // | |         |                 ???
                // | |         nSamplesPerSec
                // | wBlockAlign
                // wBitsPerSample

                codec     = (MiniFormatTag)((format) & ((1 << 1) - 1));
                channels  = (format >> (1)) & ((1 << 3) - 1);
                rate      = (format >> (1 + 3 + 1)) & ((1 << 18) - 1);
                alignment = (format >> (1 + 3 + 1 + 18)) & ((1 << 8) - 1);
                //bits = (format >> (1 + 3 + 1 + 18 + 8)) & ((1 << 1) - 1);

                /*} else if(wavebankheader.dwVersion == 23) { // I'm not 100% sure if the following is correct
                 *  // version 23:
                 *  // 1000000000 001011101110000000 001 1
                 *  // | |        |                  |   |
                 *  // | |        |                  |   ???
                 *  // | |        |                  nChannels?
                 *  // | |        nSamplesPerSec
                 *  // | ???
                 *  // !!!UNKNOWN FORMAT!!!
                 *
                 *  //codec = -1;
                 *  //chans = (wavebankentry.Format >>  1) & ((1 <<  3) - 1);
                 *  //rate  = (wavebankentry.Format >>  4) & ((1 << 18) - 1);
                 *  //bits  = (wavebankentry.Format >> 31) & ((1 <<  1) - 1);
                 *  codec = (wavebankentry.Format                    ) & ((1 <<  1) - 1);
                 *  chans = (wavebankentry.Format >> (1)             ) & ((1 <<  3) - 1);
                 *  rate  = (wavebankentry.Format >> (1 + 3)         ) & ((1 << 18) - 1);
                 *  align = (wavebankentry.Format >> (1 + 3 + 18)    ) & ((1 <<  9) - 1);
                 *  bits  = (wavebankentry.Format >> (1 + 3 + 18 + 9)) & ((1 <<  1) - 1); */
            }
            else
            {
                // 0 00000000 000111110100000000 010 01
                // | |        |                  |   |
                // | |        |                  |   wFormatTag
                // | |        |                  nChannels
                // | |        nSamplesPerSec
                // | wBlockAlign
                // wBitsPerSample

                codec     = (MiniFormatTag)((format) & ((1 << 2) - 1));
                channels  = (format >> (2)) & ((1 << 3) - 1);
                rate      = (format >> (2 + 3)) & ((1 << 18) - 1);
                alignment = (format >> (2 + 3 + 18)) & ((1 << 8) - 1);
                //bits = (info.Format >> (2 + 3 + 18 + 8)) & ((1 << 1) - 1);
            }
        }
Пример #2
0
        private void PlatformInitializeXact(MiniFormatTag codec, byte[] buffer, int channels, int sampleRate, int blockAlignment, int loopStart, int loopLength, out TimeSpan duration)
        {
            if (codec == MiniFormatTag.Adpcm)
            {
                PlatformInitializeAdpcm(buffer, 0, buffer.Length, sampleRate, (AudioChannels)channels, (blockAlignment + 16) * channels, loopStart, loopLength);
                duration = TimeSpan.FromSeconds(SoundBuffer.Duration);
                return;
            }

            throw new NotSupportedException("Unsupported sound format!");
        }
Пример #3
0
        // Only used from XACT WaveBank.
        internal SoundEffect(MiniFormatTag codec, byte[] buffer, int channels, int sampleRate, int blockAlignment, int loopStart, int loopLength)
        {
            // Handle the common case... the rest is platform specific.
            if (codec == MiniFormatTag.Pcm)
            {
                _duration = TimeSpan.FromSeconds((float)buffer.Length / (sampleRate * blockAlignment));
                PlatformInitializePcm(buffer, 0, buffer.Length, sampleRate, (AudioChannels)channels, loopStart, loopLength);
                return;
            }

            PlatformInitializeXact(codec, buffer, channels, sampleRate, blockAlignment, loopStart, loopLength, out _duration);
        }
Пример #4
0
        private void PlatformInitializeXact(MiniFormatTag codec, byte[] buffer, int channels, int sampleRate, int blockAlignment, int loopStart, int loopLength, out TimeSpan duration)
        {
            if (codec == MiniFormatTag.Adpcm)
            {
                duration = TimeSpan.FromSeconds((float)loopLength / sampleRate);

                CreateBuffers(new WaveFormatAdpcm(sampleRate, channels, blockAlignment),
                              ToDataStream(0, buffer, buffer.Length),
                              loopStart,
                              loopLength);

                return;
            }

            throw new NotSupportedException("Unsupported sound format!");
        }
Пример #5
0
        // Only used from XACT WaveBank.
        internal SoundEffect(MiniFormatTag codec, byte[] buffer, int channels, int sampleRate, int blockAlignment, int loopStart, int loopLength)
        {
            Initialize();
            if (_systemState != SoundSystemState.Initialized)
            {
                throw new NoAudioHardwareException("Audio has failed to initialize. Call SoundEffect.Initialize() before sound operation to get more specific errors.");
            }

            // Handle the common case... the rest is platform specific.
            if (codec == MiniFormatTag.Pcm)
            {
                _duration = TimeSpan.FromSeconds((float)buffer.Length / (sampleRate * blockAlignment));
                PlatformInitializePcm(buffer, 0, buffer.Length, 16, sampleRate, (AudioChannels)channels, loopStart, loopLength);
                return;
            }

            PlatformInitializeXact(codec, buffer, channels, sampleRate, blockAlignment, loopStart, loopLength, out _duration);
        }
Пример #6
0
 private void PlatformInitializeXact(MiniFormatTag codec, byte[] buffer, int channels, int sampleRate, int blockAlignment, int loopStart, int loopLength, out TimeSpan duration)
 {
     throw new NotSupportedException("Unsupported sound format!");
 }