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

Luke Iannini lukexipd at gmail.com
Mon Dec 21 01:38:49 UTC 2015


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151220/1ef882fe/attachment-0001.html>


More information about the Beginners mailing list