Inheritance: IDisposable
Exemplo n.º 1
0
 public SoundItem(String sourcefile)
 {
     OggStream ostream = new OggStream(sourcefile);
     ostream.Prepare();
     useStream = ostream;
     //AL.BufferData(_Buffer,ostream.g)
 }
Exemplo n.º 2
0
        public bool FillBuffer(OggStream stream, int bufferId)
        {
            int readSamples;

            lock (readMutex)
            {
                readSamples = stream.Reader.ReadSamples(readSampleBuffer, 0, BufferSize);
                CastBuffer(readSampleBuffer, castBuffer, readSamples);
            }
            AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
                          readSamples * sizeof(short), stream.Reader.SampleRate);
            ALHelper.Check();

            if (readSamples == BufferSize)
            {
                Logger.Log(LogEvent.NewPacket, stream);
            }
            else
            {
                Logger.Log(LogEvent.LastPacket, stream);
            }
            Logger.Log(LogEventSingle.MemoryUsage, () => GC.GetTotalMemory(true));

            return(readSamples != BufferSize);
        }
Exemplo n.º 3
0
 public override void Log(LogEvent eventType, OggStream stream)
 {
     var p = streamOffset[stream];
     switch (eventType)
     {
         case LogEvent.BeginPrepare:
             Write("(*", 7, p.Y);
             SetHOffset(stream, 9);
             break;
         case LogEvent.EndPrepare:
             Write(")", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.Play:
             Write("{", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.Stop:
             Write("}", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.Pause:
             Write("[", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.Resume:
             Write("]", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.Empty:
             Write(new string(Enumerable.Repeat(' ', Console.BufferWidth - 6).ToArray()), 6, p.Y);
             SetHOffset(stream, 7);
             break;
         case LogEvent.NewPacket:
             Write(".", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.LastPacket:
             Write("|", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
         case LogEvent.BufferUnderrun:
             Write("!", p.X, p.Y);
             SetHOffset(stream, p.X + 1);
             break;
     }
 }
Exemplo n.º 4
0
        internal Song(string name, string file, AudioFormat format = AudioFormat.Ogg)
        {
            if (format != AudioFormat.Ogg)
                throw new NotImplementedException("Support for formats other than ogg is not yet implemented.");

            _name = name;
            _file = file;

            try
            {
                _stream = new OggStream(_file);
                _stream.Prepare();
            }
            catch (InvalidDataException)
            {
                _stream.Dispose();
                _stream = new OggStream(_file);
                _stream.Prepare();
            }
        }
Exemplo n.º 5
0
        public void Dispose()
        {
            if (_stream == null)
                return;

            Stop();
            _stream.Dispose();
            _stream = null;
        }
Exemplo n.º 6
0
        static void Main()
        {
            #if TRACE
            Trace.Listeners.Add(new ConsoleTraceListener());
            #endif
            Console.WindowHeight = StreamFiles.Length + 12;

            Console.WriteLine("Pr[e]pare, [P]lay, [S]top, Pa[u]se, [R]esume, [L]oop toggle, [Q]uit");
            Console.WriteLine("Faders (in/out) : Low-pass filter [F]/[G], Volume [V]/[B]");
            Console.WriteLine("[Up], [Down] : Change current sample");
            Console.WriteLine("[Shift] + Action : Do for all " + StreamFiles.Length + " streams");

            var logger = new ConsoleLogger();
            logger.Write(" #  FX Buffering", 0, 8);

            using (new AudioContext())
            using (var streamer = new OggStreamer(65536))
            {
                streamer.Logger = logger;
                ALHelper.CheckCapabilities(logger);

                bool quit = false;

                var streams = new OggStream[StreamFiles.Length];

                for (int i = 0; i < StreamFiles.Length; i++)
                {
                    streams[i] = new OggStream(StreamFiles[i]) { Logger = logger };
                    logger.SetStreamIndex(streams[i], i);
                    logger.Write((i + 1).ToString(), 1, 10 + i);
                }
                logger.Write(">", 0, 10);
                foreach (var s in streams)
                    s.Prepare();

                int sIdx = 0;
                var activeSet = new List<OggStream>();

                while (!quit)
                {
                    var input = Console.ReadKey(true);

                    activeSet.Clear();
                    if ((input.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift)
                        activeSet.AddRange(streams);
                    else
                        activeSet.Add(streams[sIdx]);

                    var lower = char.ToLower(input.KeyChar);
                    if (input.Key == ConsoleKey.UpArrow) lower = '-';
                    if (input.Key == ConsoleKey.DownArrow) lower = '+';

                    switch (lower)
                    {
                        case 'e': activeSet.ForEach(x => x.Prepare()); break;
                        case 'p': activeSet.ForEach(x => x.Play()); break;
                        case 'u': activeSet.ForEach(x => x.Pause()); break;
                        case 's': activeSet.ForEach(x => x.Stop()); break;
                        case 'r': activeSet.ForEach(x => x.Resume()); break;

                        case 'l':
                            int index = 0;
                            activeSet.ForEach(s =>
                            {
                                s.IsLooped = !s.IsLooped;
                                logger.Write(s.IsLooped ? "L" : " ", 3, 10 + index++);
                            });
                            break;

                        case 'v': FadeVolume(activeSet, true, 1, logger); break;
                        case 'b': FadeVolume(activeSet, false, 1, logger); break;

                        case 'f': FadeFilter(activeSet, true, 1, logger); break;
                        case 'g': FadeFilter(activeSet, false, 1, logger); break;

                        case '+':
                            logger.Write(" ", 0, 10 + sIdx);
                            sIdx++;
                            if (sIdx > streams.Length - 1) sIdx = 0;
                            logger.Write(">", 0, 10 + sIdx);
                            break;

                        case '-':
                            logger.Write(" ", 0, 10 + sIdx);
                            sIdx--;
                            if (sIdx < 0) sIdx = streams.Length - 1;
                            logger.Write(">", 0, 10 + sIdx);
                            break;

                        case 'q':
                            quit = true;
                            foreach (var cts in filterFades.Values) cts.Cancel();
                            foreach (var cts in volumeFades.Values) cts.Cancel();
                            foreach (var s in streams) s.Stop(); // nicer and more effective
                            foreach (var s in streams) s.Dispose();
                            break;
                    }
                }
            }
        }
Exemplo n.º 7
0
 void SetHOffset(OggStream stream, int offset)
 {
     var originalOffset = streamOffset[stream];
     streamOffset[stream] = new Point(offset, originalOffset.Y);
 }
Exemplo n.º 8
0
 public void SetStreamIndex(OggStream stream, int index)
 {
     streamOffset.Add(stream, new Point(6, index + 10));
 }
 public abstract void Log(LogEvent eventType, OggStream stream);
Exemplo n.º 10
0
 internal bool AddStream(OggStream stream)
 {
     lock (iterationMutex)
         return(streams.Add(stream));
 }
Exemplo n.º 11
0
 internal bool RemoveStream(OggStream stream)
 {
     lock (iterationMutex)
         return streams.Remove(stream);
 }
Exemplo n.º 12
0
 internal bool AddStream(OggStream stream)
 {
     lock (iterationMutex)
         return streams.Add(stream);
 }
Exemplo n.º 13
0
        public bool FillBuffer(OggStream stream, int bufferId)
        {
            int readSamples;
            lock (readMutex)
            {
                readSamples = stream.Reader.ReadSamples(readSampleBuffer, 0, BufferSize);
                CastBuffer(readSampleBuffer, castBuffer, readSamples);
            }
            AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
                          readSamples * sizeof (short), stream.Reader.SampleRate);
            ALHelper.Check();

            if (readSamples == BufferSize)  Logger.Log(LogEvent.NewPacket, stream);
            else                            Logger.Log(LogEvent.LastPacket, stream);
            Logger.Log(LogEventSingle.MemoryUsage, () => GC.GetTotalMemory(true));

            return readSamples != BufferSize;
        }
Exemplo n.º 14
0
 public abstract void Log(LogEvent eventType, OggStream stream);
Exemplo n.º 15
0
 public void Log(LogEvent eventType, OggStream stream)
 {
 }
Exemplo n.º 16
0
 internal bool RemoveStream(OggStream stream)
 {
     lock (iterationMutex)
         return(streams.Remove(stream));
 }
Exemplo n.º 17
0
        private void PlaySoundThread(string assetName, bool loop)
        {
            string fileName = this.GetAsset (assetName).fileName;
            string ext = fileName.Substring(fileName.LastIndexOf(@".") + 1);

            if (ext == "wav") {
                int channels, bits_per_sample, sample_rate;
                byte[] data = OpenTKUtils.LoadWave (fileName, out channels, out bits_per_sample, out sample_rate);

                int buffer = AL.GenBuffer ();
                int source = AL.GenSource ();
                AL.BufferData (buffer, OpenTKUtils.WaveFormat (channels, bits_per_sample), data, data.Length, sample_rate);

                AL.Source (source, ALSourcei.Buffer, buffer);
                AL.Source (source, ALSourceb.Looping, loop);

                AL.SourcePlay (source);

                int state;

                do {
                    Thread.Sleep (300);
                    AL.GetSource (source, ALGetSourcei.SourceState, out state);
                } while ((ALSourceState)state == ALSourceState.Playing);

                AL.SourceStop (source);
                AL.DeleteSource (source);
                AL.DeleteBuffer (buffer);
            } else if (ext == "ogg") {
                using (var streamer = new OggStreamer ()) {
                    OggStream stream = new OggStream (fileName);
                    stream.Prepare ();
                    stream.Play ();
                }
            } else {
                throw new NotImplementedException($"Support for audio extension '{ext}' is not implemented.");
            }
        }
Exemplo n.º 18
0
 public void Log(LogEvent eventType, OggStream stream)
 {
 }