Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Generating tones and pitches ie square sine in x hz / gps lat long
-
How do generate sounds in order to write an audio modem for ax.25.? I obviously need to generate tones.
I really think this app is limited and frankly a poor mans xcode off the back of ios not available. The gps function barely works if at all! -
Obviously I need a fast performing synthesiser but as for the gps I'm doomed. Ironically I'm just trying a slow 1200baud rate version somehow if at all. I think actual abilities to do certain old things hardware was only capable of tests a programming IDE.
-
Obviously you won't be able to write a audio modem with pythonista, since there is no microphone support! You could modulate and write to a wav, but I believe the sound module right now only plays mp3, correct me if I'm wrong somebody. You could always create a .wav, then upload to a web service that does wav to mp3 conversion...
as for GPS, why not explain what you are trying to do, and what the problems are? For instance, have you authorized the app to use location? Did you call
start_updates
beforeget_location
? Does your device actually have a gps, or only wifi based location? -
I am trying to make an aprs script which encodes an ax.25 to reveal locations via transmitting signals via audio then radio. Comprehend.
-
Do I understand this correctly: you are trying to write one script that constantly transmits its location via radio, then have another script which picks up these signals and displays the location data?
First of all you'd need external hardware to do the radio transmission, which won't be usable with Pythonista. Unless of course it worked via the headphone output, in which case you still could only send - as mentioned above, Pythonista doesn't have microphone support, and most audio input devices don't work correctly with the combined in/out audio jack of iDevices.
PS:
@JonB: You should enclose function names and such in grave accents, that way they won't be formatted with Markdown. e. g.`function_name_here()`
becomes
function_name_here()
-
Actually, it looks like the wave module is not actually included in pythonista, though the docs say it is. However, the sounds module does actually play wav files.
So you should be able to fill out your own header and write to a wav file.
http://scytale.name/files/2007/11/eurosignal.py
for an example of doing this, or more detail on wav format
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/Afsk can be done using
https://github.com/jmcmellen/sameeas
This depends on wave (you'll have to modify to write wav file), and optional pyaudio which won't work either.The location module seems to work in loops within a scene, see forums, though not in a loop in a script. So I think you'll write a scene that grabs location, encode, write to wav file, then play wav. You could also just use aprs-is, but I assume you don't have ready internet available, otherwise why use audio?
-
The
wave
module will be included in 1.5, though it actually doesn't help very much on iOS because there's no way to play uncompressed .wav files (and thewave
module doesn't support compression). -
Sure about that? I just created a short pcm wav, and played it with
sound.play_effect
, seemed to work fine! -
JonB... It would be fascinating to understand how you do this if you have a code snippet that you would be willing to share.
-
See the eurosignal.py I posted above.
It wants to run as a script, so just manually set num filename and wav filename.
Then, play withplay_effect'
. I have not tried any other sample rates, or any more interesting tones, etc -
For what it's worth... Uncompressed waves work, and
play_effect
plays them without renaming to caf.# generate wav file containing sine waves import math, wave, array duration = 3 # seconds freq = 440 # of cycles per second (Hz) (frequency of the sine waves) volume = 100 # percent data = array.array('h') # signed short integer (-32768 to 32767) data sampleRate = 44100.0 # of samples per second (standard) numChan = 1 # of channels (1: mono, 2: stereo) dataSize = 2 # 2 bytes because of using signed short integers => bit depth = 16 numSamplesPerCyc = (sampleRate / freq) numSamples = int(sampleRate * duration) for i in range(numSamples): sample = 32767 * float(volume) / 100 sample *= math.sin(math.pi * 2 * (i / numSamplesPerCyc)) data.append(int(sample)) f = wave.open('440hz.wav', 'w') f.setparams((numChan, dataSize, sampleRate, numSamples, "NONE", "Uncompressed")) f.writeframes(data.tostring()) f.close() import sound sound.play_effect('440hz.wav')
One issue, is that play_effect appears to cache files, so a new file name is needed each time if you are modifying params.
-
Interesting! To work around the
play_effect
caching, you could also do something like this:# ... import sound player = sound.Player('440hz.wav') player.play()
-
omz: do you know about the pyo module ? It's quite powerful and would be a great addition to pythonista ! You can build quite complex synths and effects with it.
Website: http://ajaxsoundstudio.com/software/pyo/
Source: https://code.google.com/p/pyo/ -
Pyo is GPL v3, and written in c... So looks like a no go.
-
JonB: isn't numpy also written in C ?
-
Thanks for the snippets above, they're really helpful!
FWIW, one can generate that test sample a lot faster using numpy as follows:
import numpy as np th=np.linspace(0, 2*np.pi*freq*duration, numSamples, endpoint=False) data = (32767*volume/100.0*np.sin(th)).astype(np.int16)