Welcome, Guest
Username: Password: Remember me

TOPIC: Audio support for PyRadmon

Audio support for PyRadmon 2 years 4 months ago #151

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 176
  • Thank you received: 26
  • Karma: 9
This topic will handle the addition of audio within PyRadmon.

Project moved to SourceForge!
SourceForge project page: PyRadmon Reborn

I will be using either PyAudio for this script.

Installation:
1> Use your package manager to install PortAudio. (http://www.portaudio.com/)
2> Install PyAudio (http://people.csail.mit.edu/hubert/pyaudio)
3> Run PyRadmon.py once (python ./pyradmon.py)
4> Configure all the settings in config.txt
5> Run PyRadmon.py again and monitor. :) (python ./pyradmon.py)

Download:
Single counter:

File Attachment:

File Name: AudioPyRadmon.zip
File Size: 6 KB

Two counters:

File Attachment:

File Name: AudioMultiPyRadmon.zip
File Size: 7 KB


Other:
Fully functional now, a great shout-out to Dan for initial help and hints.
Thanks to PyAudio, Python and Russell Borogove @ Stack Overflow for the library's and good passive help.
Last Edit: 2 years 3 months ago by ThibmoRozier.
The administrator has disabled public write access.
The following user(s) said Thank You: mw0uzo

Audio support for PyRadmon 2 years 4 months ago #152

  • mw0uzo
  • mw0uzo's Avatar
  • OFFLINE
  • Moderator
  • Posts: 818
  • Thank you received: 166
  • Karma: 22
I can help.
When I run the script for the first time I get
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\Daniel>cd Desktop

C:\Users\Daniel\Desktop>MultiPyRadmon.py
  File "C:\Users\Daniel\Desktop\MultiPyRadmon.py", line 826
    for n in range(0, n < bytesrecorded; n = n + 2):
                                       ^
SyntaxError: invalid syntax

C:\Users\Daniel\Desktop>
The administrator has disabled public write access.

Audio support for PyRadmon 2 years 4 months ago #153

  • mw0uzo
  • mw0uzo's Avatar
  • OFFLINE
  • Moderator
  • Posts: 818
  • Thank you received: 166
  • Karma: 22
'deadticker' needs to be initialised to 1 or pulse detection won't work properly
The administrator has disabled public write access.

Audio support for PyRadmon 2 years 4 months ago #154

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 176
  • Thank you received: 26
  • Karma: 9
My bad. ^_^
The administrator has disabled public write access.

Audio support for PyRadmon 2 years 4 months ago #155

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 176
  • Thank you received: 26
  • Karma: 9
-Deep zen sigh- Soo, basically I am stuck on this:
Problem with audio port => geiger 1:

	'float' object is not iterable 

Exiting

I fixed all other tinyminy issues. ^_^
Forgot to format some C# parts to python before.
Updated file is up now, helpies? Q.Q
The administrator has disabled public write access.

Audio support for PyRadmon 2 years 4 months ago #156

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 176
  • Thank you received: 26
  • Karma: 9
So, basically I need a helping hand on this total confusion of a logic....
(No idea who made it up but it got me and a math freak brain-fart. :P )
Problem section:
...
self.amplitudebuffer=None
        self.envelope = float(0)
        self.detectwidthcounter = 0
        self.lastrisingedge = float(0)
        self.lastfallingedge = float(0)
        self.lastdeadtimeedge = float(0)
        self.lastminwidthedge = float(0)
        self.last = False
        self.onecaptured = False
        self.deadticker = 1
        cpm=25
        stream = self.p.open(format=self.FORMAT, channels=self.CHANNELS, rate=self.RATE, input=True, frames_per_buffer=self.CHUNK)
        frames = []
        for i in range(0, int(self.RATE / self.CHUNK * self.RECORD_SECONDS)):
            dataAudio = stream.read(self.CHUNK)
            frames.append(dataAudio)
        try:
            bytesrecorded = self.CHUNK * self.RECORD_SECONDS
            
            sampletime = float(float(1.0) / float(self.RATE))
            detectlevel = float(0.025)
            
            minwidth = int(math.fsum((float(5) / float(1000)) / sampletime))
            deadtime = int(math.fsum((float(5) / float(1000)) / sampletime))
            
            radcount = 0
            
            self.lastrisingedge = -1
            self.lastfallingedge = -1
            self.lastdeadtimeedge = -1
            self.lastminwidthedge = -1

            arrayptr = 0

            value = 0.0
            attack = 0.001
            release = 0.004
            ga = math.exp(-1 / (self.RATE * attack))
            gr = math.exp(-1 / (self.RATE * release))

            self.onecaptured = False

            svalue=0
            for n in range(0, bytesrecorded):
                # get your data into 'input'
                svalue = (frames[n + 1] < 8) or frames[n] # Used to be svalue = (short)((e.Buffer[n + 1] << 8) | e.Buffer[n]);

                if svalue == (-32768):
                    svalue = (-32767)

                if svalue > 0:
                    value = math.fabs(svalue) / float(32767)

                if svalue < 0:
                    value = math.fabs(svalue) / float(32768)

                if self.envelope < value:
                    self.envelope *= ga
                    self.envelope += (1.0 - ga) * value
                else:
                    self.envelope *= gr
                    self.envelope += (1.0 - gr) * value
                    
                self.amplitudebuffer[arrayptr] = math.floor(self.envelope)
                
                if self.amplitudebuffer[arrayptr] >= detectlevel:
                    if self.detectwidthcounter == 0:
                        self.lastrisingedge = arrayptr * sampletime
                    self.detectwidthcounter = self.detectwidthcounter + 1
                    if self.detectwidthcounter >= minwidth:
                        radcount = radcount + 1
                        self.onecaptured = True
                        self.lastminwidthedge = arrayptr * sampletime
                    self.last = True
                else:
                    if self.last==True:
                        self.lastfallingedge = arrayptr * sampletime
                        self.deadticker = deadtime
                    self.detectwidthcounter = 0
                    self.deadticker = self.deadticker - 1
                    self.last = False
                if self.deadticker == 0:
                    self.lastdeadtimeedge = arrayptr * sampletime
                arrayptr = arrayptr + 1

                n = n + 2
		
                cpm = radcount
		
        except Exception as ex:
            print "Problem with audio port => geiger 1:\r\n\t", str(ex),"\r\nExiting\r\n"
            stream.stop_stream()
            stream.close()
            self.p.terminate()
            self.stop()
            sys.exit(1)
...
The administrator has disabled public write access.
Time to create page: 0.074 seconds
Powered by Kunena Forum