[Haskell-beginners] Problem reading sound data from mic with TChan

Martin Vlk martin at vlkk.cz
Mon Dec 21 07:07:10 UTC 2015


Oh doh, #@!"%^ damn it! ;-)
Yes, you are absolutely right, many thanks for the help!

Martin

Luke Iannini:
> Hi Martin,
> 
> On line 63 http://lpaste.net/147522#line63, when you do
> 
> let sndChan = newTChan
> 
> 
> you're not actually creating a new TChan, but rather creating a
> reference to the STM action that creates new TChans.
> 
> 
> So this means that e.g. on line 71 http://lpaste.net/147522#line71,
> you are creating a new channel every time with
> 
> ch <- sndChan
> 
> 
> Instead, you want to do:
> 
> sndChan <- newTChanIO
> 
> (or,
> 
> sndChan <- atomically newTChan
> 
> )
> 
> 
> And then pass that value to your other functions, which will just take
> TChan [Int32] rather than STM (TChan [Int32])
> 
> 
> Here's what I mean:
> 
> http://lpaste.net/diff/147522/147557
> 
> 
> Hope that helps!
> 
> 
> 
> On Sun, Dec 20, 2015 at 9:24 AM, Martin Vlk <martin at vlkk.cz> wrote:
> 
>> Hi, I am working on a little toy project related to controlling graphics
>> display based on data from the computer microphone.
>>
>> I am basing the whole thing on concepts from game programming, so I have
>> a main loop which reads inputs, updates the world state and generates
>> outputs.
>>
>> As part of inputs there is microphone. I read data from it using the
>> pulse-simple library. The "simpleRead" function blocks if there is not
>> enough data available so I can't use it directly in the main loop or I
>> risk delays.
>>
>> So I figured I'll use a separate thread to read from the mic and write
>> data into a TChan. The main loop in separate thread then can read from
>> the TChan as needed and test for availability of data to avoid delaying
>> the main loop.
>>
>> Here is my current code: http://lpaste.net/147522
>>
>> The data is written into TChan in the "handleMic" function and read from
>> the TChan on line 85.
>>
>> The problem I have is that the TChan never seems to contain any data
>> when I read from it and that confuses me. Why?
>>
>> Does anyone see where is my problem?
>>
>> Many Thanks
>> Martin
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 


More information about the Beginners mailing list