Coder Social home page Coder Social logo

pysinewave's People

Contributors

daviddavini avatar dependabot[bot] avatar pmusacchio avatar potter-s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pysinewave's Issues

Save generated sound to file

Hi,

first of all, nice project!

Not an issue but a question / feature request: is it possible to store the generated sound in a file?

Thanks! :-)

EDIT: see my draft here https://github.com/CodeFinder2/pysinewave/commits/master I can create a PR if you are fine with it.

EDIT: changed the code a bit to be more flexible (it now allows to retrieve the collected data so that it can be stored in a (WAV) file by the user of the library).

IndexError: index 1 is out of bounds for axis 0 with size 1

Hi,

I sometime get the following exception:

ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
output underflow
From cffi callback <function _StreamBase.init.<locals>.callback_ptr at 0x7f2ce9c0f5e0>:
Traceback (most recent call last):
  File "/home/abo/.local/lib/python3.8/site-packages/sounddevice.py", line 856, in callback_ptr
    return _wrap_callback(callback, data, frames, time, status)
  File "/home/abo/.local/lib/python3.8/site-packages/sounddevice.py", line 2678, in _wrap_callback
    callback(*args)
  File "/home/abo/.local/lib/python3.8/site-packages/pysinewave/sinewave.py", line 26, in <lambda>
    self.output_stream = sd.OutputStream(channels=1, callback=lambda *args: self._callback(*args),
  File "/home/abo/.local/lib/python3.8/site-packages/pysinewave/sinewave.py", line 37, in _callback
    data = self.sinewave_generator.next_data(frames)
  File "/home/abo/.local/lib/python3.8/site-packages/pysinewave/sinewave_generator.py", line 61, in next_data
    delta_time = time_array[1] - time_array[0]
IndexError: index 1 is out of bounds for axis 0 with size 1

It seemed to be related to this line of code:

    def next_data(self, frames):
        '''Get the next pressure array for the given number of frames'''

        # Convert frame information to time information
        time_array = utilities.frames_to_time_array(0, frames, self.samplerate)
        delta_time = time_array[1] - time_array[0]  # HERE
        # ...

where time_array has length < 2. I quickly fixed it with:

    def next_data(self, frames):
        '''Get the next pressure array for the given number of frames'''

        # Convert frame information to time information
        time_array = utilities.frames_to_time_array(0, frames, self.samplerate)
        if len(time_array) >= 2:
            delta_time = time_array[1] - time_array[0]
        else:
            delta_time = 0
        # ...

but not sure whether this is a good way to handle it (especially wrt. subsequent code lines).

EDIT: see my commit here: CodeFinder2@bbafdf7 If you consider it okay, I can provide a PR.

Mono/Stereo sounds

Hello,

Is there a way to play different sines waves on different channels ? Or at least to stack two mono SineWave instances to create a stereo sound ? For instance, I'd like to play one sine on the left ear of the headset and another one on the right ear.

Thanks a lot !

sine.set_voume isn't working

Just installed pysinewave and I'm a huge fan so far but I'm having a problem with sine.set_volume not working. I'm not sure if I'm just not using it correctly but here's the code I'm using:

import time
from pysinewave import SineWave

note = 12
vol = 30
sine = SineWave(pitch=note, pitch_per_second=20)

sine.set_volume(-100)

sine.play()

time.sleep(1)

sine.set_pitch(+14)

time.sleep(1)

sine.set_volume(-10)

time.sleep(0.5)

while True:
    sine.set_pitch(+1)
    time.sleep(0.075)
    sine.set_pitch(-1)
    time.sleep(0.075)

Originally, I was going to change the value of the volume with decibels from 30 to 20 or something similar just to test it out but it wasn't working so I went to extremes and tried 0 for the input as well as what I have above.

I'm using PyCharm to write my code on a M1 MacBook Air.

set_amplitude def is missing from sinewave.py

Presumably there should be one that calls the appropriate set_amplitude in sinewave_generator.py, but there's no linking def.
Currently docs suggest SineWave.set_amplitude(percent) as possible, but SineWave object is missing that attribute.

Setting initial frequency for signal

Hello and thank you very much for putting this together!

I am very interested in using the SineWave.set_frequency(hertz) and SineWave.set_amplitude(percent) functions for a software approach to (specifically this) heterodyne frequency shifting technique.

Thus, I'm hoping to generate some sine signals with specific frequencies, though I'm unsure exactly how to get the SineWave to initialize with the frequency that I'm setting in my SineWave.set_frequency(hertz) function.

The code I'm tinkering with is below. The goal for now is simply to generate a SineWave with the specified frequency.

I apologize in advance for any difficulty there might be in getting me to understand such an esoteric concept and for sucking at python! (There is a real chance than I'm just shitty at Python and have some syntax issues when trying to use the function.)

Take 1:

import time
from pysinewave import SineWave

# Create a sine wave
sinewave = SineWave()

# Set the frequency
sinewave.set_frequency(9000)

# Play the sound
sinewave.play()
time.sleep(2)
sinewave.stop()
exit()

The script above eventually reaches the 9000Hz I'm aiming for, but begins with a much lower default SiveWave from which the frequency shifts up to my specified frequency.

Take 2:

import time
from pysinewave import SineWave

# Create a sine wave
sinewave = SineWave.set_frequency(9000)

# Play the sound
sinewave.play()
time.sleep(2)
sinewave.stop()
exit()

The second attempt (in the script above) fails with this traceback:

Traceback (most recent call last):
  File "/home/patrick/./sinewave.py", line 5, in <module>
    sinewave = SineWave.set_frequency(9000)
TypeError: set_frequency() missing 1 required positional argument: 'frequency'

Again, I'm really sorry if you've made this really easy for folks who are a bit more python-savvy than I to discern for themselves how to do this, and I certainly don't want my inquiry to imply any deficit in the documentation -- on the contrary, I appreciate the time taken to funnel most users towards using pitch over frequency. For any other use case, I would certainly stay within the recommended setup, though I think the only way to generate these ultrasonic frequencies is to be explicit using a Hertz unit.

My very best regards and another thanks for this great toolset~~
Patrick

Exporting to audio file

Hey there! I've just discovered your script and I love it. It is exactly what I need for a project of mine, although I need to go one step further and save the generated sinewave as an audio file. Is there an easy way to do this within your package? I'm asking so I don't have to work on something that's been solved already.

Either way, thank you v much!

Pitch/Frequency Conversion

If this isn't the right place for this I apologize, but in the readme under "A Note on Pitch on Volume" it gives the conversion from pitch to frequency as frequency = 440 * 2^((pitch-9)/2). I think this is a typo, as it should probably be frequency = 440 * 2^((pitch-9)/12). This isn't the most important since it's correct in the code, but it did confuse me for a little.

Otherwise thank you for this, it's a helpful tool.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.