Пример #1
0
        /// <summary>
        /// Воспроизведение
        /// </summary>
        /// <param name="parIsLooped">Зациклить воспроизведение?</param>
        public void Play(bool parIsLooped)
        {
            AL.Source(AlSource, ALSourceb.Looping, parIsLooped);
            AL.SourcePlay(AlSource);

            OpenAlManager.CheckForError(
                $"Cannot start playback: {AlSource} - {_linkedAssetData.ActualAssetMetadata.FilePath}");
        }
Пример #2
0
        /// <summary>
        /// Стандартный конструктор
        /// </summary>
        /// <param name="parAssetMetadata">Метаданные об ассете</param>
        /// <param name="parBinaryData">Аудио данные в бинарном формате</param>
        public AssetDataOpenTkWaveSound(AssetMetadataOpenTk parAssetMetadata, byte[] parBinaryData) : base(parAssetMetadata)
        {
            OpenAlManager.GetInstance();

            if (Path.GetExtension(parAssetMetadata.FilePath) == ".ogg")
            {
                AudioFormatProvider = new AudioFormatProviderOgg();
            }
            else
            {
                AudioFormatProvider = new AudioFormatProviderWav(parBinaryData);
            }

            AudioFormatProvider.InitAudioData(this);
        }
Пример #3
0
        /// <summary>
        /// Инициализация и первоначальная загрузка аудио данных
        /// </summary>
        /// <param name="parLinkedOpenTkSound">Аудио данные OpenTK</param>
        public void InitAudioData(AssetDataOpenTkWaveSound parOpenTkWaveSound)
        {
            _linkedAssetData = parOpenTkWaveSound;

            AlBuffer = AL.GenBuffer();
            AlSource = AL.GenSource();

            OpenAlManager.CheckForError("AL loading not ready...");

            using (MemoryStream ms = new MemoryStream(AudioBinaryData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    // проверка заголовка RIFF
                    string signature = new string(br.ReadChars(4));
                    if (signature != "RIFF")
                    {
                        throw new NotSupportedException("Specified stream is not a wave file.");
                    }

                    int riffChunckSize = br.ReadInt32();

                    string format = new string(br.ReadChars(4));
                    if (format != "WAVE")
                    {
                        throw new NotSupportedException("Specified stream is not a wave file.");
                    }

                    // проверка заголовка WAVE
                    string formatSignature = new string(br.ReadChars(4));
                    if (formatSignature != "fmt ")
                    {
                        throw new NotSupportedException("Specified wave file is not supported.");
                    }

                    int formatChunkSize = br.ReadInt32();
                    int audioFormat     = br.ReadInt16();
                    int numChannels     = br.ReadInt16();
                    int sampleRate      = br.ReadInt32();
                    int byteRate        = br.ReadInt32();
                    int blockAlign      = br.ReadInt16();
                    int bitsPerSample   = br.ReadInt16();

                    string dataSignature = new string(br.ReadChars(4));
                    if (dataSignature != "data")
                    {
                        throw new NotSupportedException("Specified wave file is not supported.");
                    }

                    int dataChunkSize = br.ReadInt32();

                    Channels      = numChannels;
                    BitsPerSample = bitsPerSample;
                    SampleRate    = sampleRate;

                    AudioBinaryData = br.ReadBytes((int)dataChunkSize);
                }
            }

            Console.WriteLine(
                $"Binary data length: {AudioBinaryData.Length}, Sample rate: {SampleRate}, {Environment.NewLine}BitsPerSample: {BitsPerSample}");
            AL.BufferData(AlBuffer, GetSoundFormat(Channels, BitsPerSample), AudioBinaryData, AudioBinaryData.Length,
                          SampleRate);

            if (!OpenAlManager.CheckForError($"Loading error: {_linkedAssetData.ActualAssetMetadata.FilePath}"))
            {
            }

            AL.Source(AlSource, ALSourcei.Buffer, AlBuffer);

            if (!OpenAlManager.CheckForError($"Loading error: {_linkedAssetData.ActualAssetMetadata.FilePath}"))
            {
                Console.WriteLine($"AL: Audio data {AlSource}:{AlBuffer} created in memory");
            }
        }
Пример #4
0
 /// <summary>
 /// Сбросить воспроизведение
 /// </summary>
 public void Reset()
 {
     AL.SourceRewind(AlSource);
     OpenAlManager.CheckForError(
         $"Cannot reset playback: {AlSource} - {_linkedAssetData.ActualAssetMetadata.FilePath}");
 }
Пример #5
0
 /// <summary>
 /// Остановить воспроизведение
 /// </summary>
 public void Stop()
 {
     AL.SourceStop(AlSource);
     OpenAlManager.CheckForError(
         $"Cannot stop playback: {AlSource} - {_linkedAssetData.ActualAssetMetadata.FilePath}");
 }