Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / SampleRateConverter / samples / mp3filestream.io
blobf3f132e07d030210329db1e4263851e8e8ebff3a
1 #!/usr/bin/env io
4 AudioMixer := Object clone do(
5 init := method(
6 self sources := List clone
7 self mixed := Sequence clone
10 newSlot("streamDestination", AudioDevice)
11 newSlot("processedSamples", 0)
12 newSlot("isRunning", false)
14 addSource := method(s, sources append(s))
15 removeSource := method(s, sources remove(s))
17 process := method(sampleCount,
18 byteCount := sampleCount * 8
19 mixed setSize(byteCount)
20 mixed zero
21 sources foreach(source,
22 while(source outputBuffer size < byteCount,
23 //writeln("source outputBuffer size = ", source outputBuffer size, " < ", byteCount)
24 yield
26 writeln("b ", source outputBuffer size)
27 mixed float32ArrayAdd(source outputBuffer)
28 source outputBuffer removeSlice(0, byteCount)
29 writeln("a ", source outputBuffer size)
31 //mixed float32ArrayDivideBy(sources size)
32 writeln("AudioMixer writing ", mixed size, " bytes to ", streamDestination type)
33 streamDestination write(mixed)
34 processedSamples = processedSamples + sampleCount
37 start := method(
38 writeln("AudioMixer start")
39 setIsRunning(true)
40 while(isRunning, process(22050)) // 1/16th of a second
43 stop := method(
44 setIsRunning(false)
48 AudioDevice open
50 MP2Decoder := AVCodec clone setCodecName("mp2")
52 AVCodec withDestination := method(dest,
53 decoder := self clone
54 decoder setStreamDestination(dest)
55 decoder @@startAudioDecoding
56 yield
57 decoder
60 SampleRateConverter withDestination := method(dest,
61 SampleRateConverter clone setStreamDestination(dest)
65 path1 := "/Users/steve/Downloads/Hp\ lovecraft/HP\ Lovecraft\ -\ The\ Fungi\ From\ Yuggoth/HP\ Lovecraft\ -\ Fungi\ From\ Yuggoth.mp3"
66 path1 := "/Users/steve/Music/Unnatural\ History\ III/Baby\ Food\ \(1994\).mp3"
67 //path2 := Path with(launchPath, "sounds/max.mp3")
69 File streamTo := method(dest,
70 setStreamDestination(dest)
71 startStreaming
72 self
75 //file1 := File with(path1) streamTo(MP2Decoder withDestination(SampleRateConverter clone setStreamDestination(AudioDevice)))
76 file1 := File with(path1)
77 file1 @@streamTo(MP2Decoder withDestination(SampleRateConverter clone))
78 //file2 := File with(path2) @streamTo(MP2Decoder withDestination(SampleRateConverter clone))
79 yield
81 writeln("AudioMixer clone")
82 mixer := AudioMixer clone
83 writeln("AudioMixer addSource ", file1 streamDestination type)
84 mixer addSource(file1 streamDestination streamDestination)
85 //mixer addSource(file2 streamDestination streamDestination)
86 writeln("AudioMixer start")
87 mixer start
89 while(1, yield)