Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate 1khz tone at 19khz using BandPass Filter at 192khz sample rate #7

Open
veso266 opened this issue Sep 29, 2017 · 0 comments
Open

Comments

@veso266
Copy link

veso266 commented Sep 29, 2017

Hi I would like to generate 1 khz sine wave which I can do fine with this code

import math        #import needed modules
import pyaudio     #sudo apt-get install python-pyaudio


#List I/O Audio ports to use
#Input Device id  0  -  Microsoft Sound Mapper - Input
#Input Device id  1  -  Line 1 (Virtual Audio Cable)
#Input Device id  2  -  Line 4 (Virtual Audio Cable)
#Input Device id  3  -  Line In (Realtek High Definitio
#Input Device id  4  -  Line 2 (Virtual Audio Cable)
#Input Device id  5  -  Microphone (Realtek High Defini
#Input Device id  6  -  Line 3 (Virtual Audio Cable)
#Output Device id  7  -  Microsoft Sound Mapper - Output
#Output Device id  8  -  Speakers (Realtek High Definiti
#Output Device id  9  -  Line 1 (Virtual Audio Cable)
#Output Device id  10  -  Line 3 (Virtual Audio Cable)
#Output Device id  11  -  Line 2 (Virtual Audio Cable)
#Output Device id  12  -  Line 4 (Virtual Audio Cable)


PyAudio = pyaudio.PyAudio     #initialize pyaudio

#See https://en.wikipedia.org/wiki/Bit_rate#Audio
BITRATE = 192000     #number of frames per second/frameset.      

FREQUENCY = 1000     #Hz, waves per second, 261.63=C4-note.
LENGTH = 10     #seconds to play sound

if FREQUENCY > BITRATE:
    BITRATE = FREQUENCY+100

NUMBEROFFRAMES = int(BITRATE * LENGTH)
RESTFRAMES = NUMBEROFFRAMES % BITRATE
WAVEDATA = ''    

#generating wawes
for x in xrange(NUMBEROFFRAMES):
 WAVEDATA = WAVEDATA+chr(int(math.sin(x/((BITRATE/FREQUENCY)/math.pi))*127+128))    

for x in xrange(RESTFRAMES): 
 WAVEDATA = WAVEDATA+chr(128)

p = PyAudio()

#Open Device for streaming
stream = p.open(format = p.get_format_from_width(1), 
                channels = 1, 
                rate = BITRATE, 
                output = True,
				output_device_index=9)

stream.write(WAVEDATA)
stream.stop_stream()
stream.close()
p.terminate()

the problem is that audio is plattered all over 192khz
audiogen

what I would like to do is move this to 19khz and cut all the junk out of the signal so it would look more like this:
audiogen2

I thought I could acomplish this with audiogen and then play generated samples using pyaudio (since you added bandpass filter) but I don't realy know how would I do this

Thanks for Anwsering and Best Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant