jbclements / rsound Goto Github PK
View Code? Open in Web Editor NEWA cross-platform sound library for DrRacket
Home Page: http://www.brinckerhoff.org/clements
License: Other
A cross-platform sound library for DrRacket
Home Page: http://www.brinckerhoff.org/clements
License: Other
When executing rsound programs with racket on the command line, the programs have a tendency to terminate before the audio is finished playing. The issue does not occur in drracket, on the command line repl, or when there is another thread keeping the program open .
I've noticed some of the example files include (sleep 60)
to keep the program from exiting right away, but this is not a sufficient workaround for circumstances where audio is being looped or generated indefinitely.
Is this functionality intended? Is there a way to fix the issue so that racket will not terminate until all pstream queues are empty?
The example with control and sawtooth in the doc of lpf/dynamic does not work.
It seems that signal+ and signal* are missing but documented.
There's a type problem there... And the test of rsound-fft-draw is commented in test-draw.rkt
At least in Racket CS 8.x I am getting the following right after requiring rsound:
racket -i -l errortrace
Welcome to Racket v8.3.0.8 [cs].
> (require rsound)
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
; Assertion #<procedure:negative?> failed on 0.0 [,bt for context]
> ,bt
; Assertion #<procedure:negative?> failed on 0.0
; errortrace...:
; context...:
; body of "/home/pmatos/.local/share/racket/8.3.0.8/pkgs/math-lib/math/private/flonum/flonum-constants.rkt"
; body of top-level
; /home/pmatos/.local/share/racket/8.3.0.8/pkgs/xrepl-lib/xrepl/xrepl.rkt:1573:0
; /home/pmatos/installs/racket-8.3dev/share/racket/collects/racket/repl.rkt:11:26
> ^D
And unfortunately even the backtrace sucks. :(
After installing rsound and all dependencies, when I try
(require rsound)
I get the error message
....\Program Files\Racket\collects\ffi\unsafe.rkt:255:20: ffi-obj: could not find export from foreign library
name: Pa_GetVersionInfo
library: C:\Users\jeffw\AppData\Roaming\Racket\8.4\pkgs\portaudio-x86_64-win32\portaudio\lib\portaudio.dll
system error: The specified procedure could not be found.; win_err=127
The file "portaudio.dll" is in fact exactly in the location specified.
resample-to-rate is provided but not documented. Useful as many web voice sounds are 8000 Hz...
raco test -p rsound
reports many issues, even on a platform with live audio, because many old files need to be fenced out, and many old API calls need to be updated. This is purely maintenance.
I was considering appending this to #16, but I figured this is different enough to warrant a new issue.
Through uncouth means, I wrangled my webcam as the default recording device but now record-sound
complains because it's trying to record with two channels and the webcam can only record with one channel.
Would you consider modifying record-sound
to allow an optional amount of channels? Something like (record-sound frames [channels 2])
?
I'm trying to suppress (but later redirect) some messages that appear on the right of the below screenshot. It appears that these are messages that come from the RSound library itself, and redirecting output via current-*-port
to nowhere doesn't have an effect.
I can still use the library fine. The problem is that I use rsound
on a different thread, and it would be competing out of band for standard ports. If I can't capture these messages somehow, then this adds noise to my logs.
Here's a copyable version of my attempt to silence rsound
noise on the left side of the screenshot. Problem is that I don't know if you'll be able to reproduce these messages because you don't have my hardware. Please tell me of any information I can provide that can help you.
#lang racket
(provide (all-defined-out))
(require "shared.rkt")
(define nowhere (open-output-nowhere))
(define-syntax-rule (silent-begin body ...)
(parameterize ([current-output-port nowhere]
[current-error-port nowhere])
body ...))
(define (dynreq s)
(silent-begin (dynamic-require 'rsound s)))
(define-syntax-rule (silent/proc id ...)
(begin
(begin
(provide id)
(define (id . args) (apply (dynreq 'id) args)))
...))
(define-syntax-rule (silent/id id ...)
(begin
(begin
(provide id)
(define id (dynreq 'id)))
...))
; Try to silence noise.
(silent/proc rs-write rs-append*)
(silent/id clap-1 snare bassdrum clap-2 kick)
On linux with Racket CS, the lookup path is
> (system-library-subpath)
#<path:x86_64-linux/cs>
but the embedded library is only in the 3m
path.
One possible fix is to make the path independent of the GC type:
> (system-library-subpath #f)
#<path:x86_64-linux>
and embed the libraries in the corresponding path.
The relevant line is here.
I have many different devices listed when I run (display-device-table)
and I have found my USB webcam, but it doesn't seem like (record-sound frames)
is using the microphone, so I can only assume it isn't being detected as my default device. Is there a way for the library to choose a recording device from the displayed device table?
...
When I'm using bluetooth headphone, no sound played when (play sound)
or (diagnose-sound-playing)
.
> (play ding)
"played sound"
> (diagnose-sound-playing)
found 1 host API(s): (paCoreAudio)
trying each one in turn.
trying api paCoreAudio:
trying to play at sample rate 44100.0:
configuration tested. Press <return> to go to next test.
trying to play at sample rate 48000.0:
configuration tested. Press <return> to go to next test.
If playback at 44100.0 failed and playback at another sample rate
succeeded using Windows 7, you probably need to manually set the
sample rate of that playback device to 44100 Hz, by right-clicking
on the volume icon and then digging through menus (properties, advanced).
but when I switch to wired headphone, everything works well. (and the output is the same)
Here's my package version information
$ raco show rsound
Installation-wide:
[none]
User-specific for installation "6.10.1":
Package Checksum Source
rsound af436efbc11497026e9... catalog...ound/master/
$ raco pkg show portaudio
Installation-wide:
[none]
User-specific for installation "6.10.1":
Package[*=auto] Checksum Source
portaudio* 3703edda0c6b9f5ef... catalog...io/master/
drracket version 6.10.1
macOS version 10.12.6
Currently, the stop
procedure stops all sounds being played by RSound. Would it be possible to implement a stop procedure that could stop an individual pstream while allowing the others to continue playing?
Perhaps a pstream-stop
procedure could stop and clear the pstream, and a pstream-pause
procedure could stop the pstream without clearing it?
I'm not sure I am yet familiar enough with how RSound interacts with portaudio to implement this myself, but I'm willing to have a go at it, provided you can point me in the right direction on where in the code base to look.
Thanks!
I've tried to run RSound on a few different Win32 systems, and I've been getting the following error:
\Program Files\Racket\collects\racket\private\kw.rkt:1168:47: pa-open-stream: Invalid device
This error does not seem to occur on Linux or MacOS systems. PortAudio supports Windows, right?
When I run an rsound program, such as the examples, in DrRacket in #lang racket
, then hitting stop doesn't stop the sound from playing. Instead, I have to close the tab to stop the sound.
With the latest nightly (minimal racket, with all "base" packages updated yesterday), I had the following error:
> racket phc ~/phc/racket-packages/phc-thesis
Welcome to Racket v6.8.0.2.
> (require rsound)
; /home/georges/.racket/snapshot/pkgs/rsound/rsound/util.rkt:19:9: module:
; identifier already imported from: "common.rkt"
; at: positive-integer?
; in: math/base
; [,bt for context]
I changed the math/base
on line 19 in util.rkt
to the following, and it seems to work fine:
racket/require
(subtract-in math/base "common.rkt")
It might be an issue with stale bytecode files on my machine, though, so it's probably best to check that you can reproduce the issue before looking into this.
Configuration
Problem
With this configuration, I can't hear anything when I execute the following code
#lang racket
(require rsound)
(play ding)
(define CHAR-CANVAS%
(class canvas%
(define/override (on-char evt)
(let ((c (send evt get-key-code)) (dc(send this get-dc)))
(send dc clear)
(print c)
(cond
((equal? c 'release)(void))
((member c '( #\a #\i #\u #\e #\o #\q #\é #\x))
(begin(set! tampon-key (cons c tampon-key)) (send dc draw-text (cadr (member (list->string (reverse tampon-key)) alphabet )) 30 30)
(send R-k-text insert (cadr (member (list->string (reverse tampon-key)) alphabet ))) (set! tampon-key '())))
((equal? c #;)(begin(send R-k-text insert "。") (set! tampon-key '())))
((equal? c #,)(begin(send R-k-text insert "、") (set! tampon-key '())))
((equal? c #()(begin(send R-k-text insert "「") (set! tampon-key '())))
((equal? c #))(begin(send R-k-text insert " 」") (set! tampon-key '())))
((equal? c #&)(begin(send R-k-text insert "々") (set! tampon-key '())))
((not(member c '(#\b #\c #\d #\f #\g #\j #\k #\m #\n #\p #\r #\i #\h #\t #\s #\w #\y #\a #\e #\o #\z #\u)))(void))
((begin (set! tampon-key (cons c tampon-key))(print tampon-key))))
))
(super-new)))
It works very well (it is for writing in hiragana katakana and other characters)
I want to add to this same canvas
a feature which tells me the position of the cursor on a text
is it possible? if yes
what is the code to add?
(define/override (on-char evt)......
Or do I need a another canvas?
in this case what will be my code?
(define/override (on-char evt)......
this in order to do something similar to a "RIKAICHAN"
Hi,
I just released some updated Racket bindings for Chipmunk:
https://github.com/thoughtstem/racket-chipmunk
I'm using racket-chipmunk and rsound together to make games, but for some reason racket-chipmunk seems to break rsound on Linux. I don't even know why that would be, but here are the steps that I've used reproduce the issue:
Assertion #<procedure:negative?> failed on 0.0
on the rsound require. The stacktrack bottoms out somewhere in "pkgs/math-lib/math/private/flonum/flonum-constants.rkt". No line number given.Feels funny. I don't know why these packages would interact weirdly with each other. And I've never seen something break in this way before. Any pointers?
(Both packages use the Racket ffi, which I suspect might be relevant. But I'm not sure.)
I'm trying to make a simple drum machine in Racket for educational purposes -- to learn about drum patterns and to learn more Racket. I'm running into problems with clicks and crackles.
I've got a DSL that I'm sort of happy with, and I'm using rsound to play the samples as appropriate: e.g.
https://github.com/ericclack/racket-beats/blob/rsound/heart1.rkt
https://github.com/ericclack/racket-beats/blob/rsound/synco1.rkt
If I increase the bpm in the heart1 example to 300+ then there are quite a few clicks. I would guess that this is because the stream I'm playing on hasn't finished the playing the previous sample before I ask it to play the next one.
I think the right way to use rsound and portaudio is for my code to do the mixing before sequencing the samples for playback. But looking at how the DSL is evolving I won't ever know which samples might overlap.
So I'm keen to play with the rsound code to see if I can fix this. I'm thinking I could add some mixing capability to the sequencer code, or quickly fade out any currently playing sample.
I'd welcome any advice or pointers...
-Eric.
Thanks for this wonderful library!
I see make-harm3tone
in the documentation, but it seems like it isn't currently exposed / provided by the library? I tried changing util.rkt to provide the function, but got an error when calling it (it uses harm3-wave
as a procedure when it's in fact a network).
(define (my-note f)
(rs-mult
(sine-window SAMPLE-TONE-LEN (* 0.1 FRAME-RATE))
(make-tone f 0.5 SAMPLE-TONE-LEN)))
There are accessors to sound like rs-ith/left but no simple way to build a (stereo ?) sound giving the ith-samples, something like (build-sound length (lambda (i) ...)). The sound API should be enough for a beginner who does not want to dive into networks (and say who wants to build a simple-low-pass filter as a simple average of x[n] and x[n-1]).
raco setup: WARNING: undefined tag in <pkgs>/rsound/rsound/rsound.scrbl:
raco setup: ((lib "rsound/main.rkt") prev)
raco setup: ((lib "rsound/main.rkt") signal/block/unsafe?)
How to reproduce:
Create a test.rkt with contents
#lang racket
(require rsound)
(displayln "This will fail")
Run raco exe test.rkt
Try running ./test
Output
collection-file-path: collection not found
collection: "portaudio/lib"
in collection directories:
context...:
/Applications/Racket v7.7/collects/racket/private/collect.rkt:26:58: fail
'#%embedded:portaudio/portaudio:: [running body]
temp35_0
for-loop
run-module-instance!
for-loop
[repeats 1 more time]
run-module-instance!
for-loop
[repeats 1 more time]
run-module-instance!
for-loop
[repeats 1 more time]
run-module-instance!
for-loop
[repeats 1 more time]
...
Because of this I am unable to create any executable files that depend on rsound, what could be the issue?
Thanks for the lib!
Current Racket HEAD (as of 1/3/23) has the following error:
[samth@huor:/tmp plt] raco make -l rsound/examples/katy-sliders
<pkgs>/rsound/rsound/examples/katy-sliders.rkt:296:1: network: expected one of these identifiers: `=' or `<='
at: <=
in: (network () (ctr <= (flexloop SONGLEN) (fetch-speed)) (delayed-ctr = (maybe-wrap ctr (fetch-delay) SONGLEN)) (out = (/ (+ (rs-ith/left SONG (floor ctr)) (rs-ith/left SONG (floor delayed-ctr))) 2)))
parsing context:
while parsing network clause rhs
term: (<= (flexloop SONGLEN) (fetch-speed))
location: <pkgs>/rsound/rsound/examples/katy-sliders.rkt:297:3
while parsing network clause
term: (ctr <= (flexloop SONGLEN) (fetch-speed))
location: <pkgs>/rsound/rsound/examples/katy-sliders.rkt:297:3
compilation context...:
/home/samth/sw/plt/racket/share/pkgs/rsound/rsound/examples/katy-sliders.rkt
location...:
/home/samth/sw/plt/racket/share/pkgs/rsound/rsound/examples/katy-sliders.rkt:297:8
context...:
/home/samth/sw/plt/racket/collects/syntax/parse/private/runtime-report.rkt:731:0: error/report
/home/samth/sw/plt/racket/collects/syntax/parse/private/runtime-report.rkt:28:0: call-current-failure-handler
This seems like a regression from 8.7, where it seems to work.
cc @rmculpepper
Installation of rsound using raco is failing because it is not liking portaudio's version specification.
$ raco pkg install rsound
Resolving "rsound" via https://download.racket-lang.org/releases/7.7/catalog/
Resolving "rsound" via https://pkgs.racket-lang.org
Using cached15910681631591068163562 for github://github.com/jbclements/RSound/master/
The following uninstalled packages are listed as dependencies of rsound:
portaudio
memoize
Would you like to install these dependencies? [Y/n/a/c/?] Y
00: Resolving "portaudio" via https://download.racket-lang.org/releases/7.7/catalog/
00: Resolving "portaudio" via https://pkgs.racket-lang.org
Resolving "memoize" via https://download.racket-lang.org/releases/7.7/catalog/
Resolving "memoize" via https://pkgs.racket-lang.org
Using cached15911164011591116401066 for github://github.com/jbclements/portaudio/master/
Using cached15911164021591116402148 for github://github.com/jbclements/memoize/master
pkg: bad version specification for portaudio: "2020-05-29"
raco pkg install: version mismatch for dependency
for package: rsound
mismatch packages:
portaudio (have 0.0, need 0.1)
For short sounds--e.g., a sound of four frames in a window of width 800--the drawing is terrible. I'm mis-rasterizing. There's weird pop-in, and zooming out causes internal errors.
I'm writing a software to inspect/analyze sounds from speech and I would like to draw the waveforms/fft in my own frame (instead of creating a new one).
I've made a change in the library to achieve what I want, but let me know if this is already supported in other way (I'm new to racket). The changes I made are here:
NeowayLabs@0f59f37
Thanks for the awesome library =)
...and maybe there are others. Also fix docs.
On OS X the example program below from the docs fails.
The error message is:
s16vector-ref: bad index 88800 for s16vector bounds of 0..88199
DrRacket highlights the form:
(rs-ith/left waveform i)
I attempted this on a 6.7 (standard) and 6.90 (racket7 branch).
#lang racket
(require rsound)
(define waveform (synth-waveform "vgame" 4))
; wrap i around when it goes off the end:
(define (maybe-wrap i)
(cond [(< i 48000) i]
[else (- i 48000)]))
; a signal that plays from a waveform:
(define loop-sig
(network (pitch)
[i = (maybe-wrap (+ (prev i 0) (round pitch)))]
[out = (rs-ith/left waveform i)]))
(signal-play
(network ()
[alternator <= square-wave 2]
[s <= loop-sig (+ (* 200 (inexact->exact alternator)) 400)]
[out = (* s 0.1)]))
After installing RSound in DrRacket 8.2, I got this error after typing this code:
#lang racket
(require rsound)
(diagnose-sound-playing)
I got this error:
. .local/share/racket/8.2/pkgs/rsound/rsound/network.rkt:6:18: only-in: identifier `beginner-<=' not included in nested require spec in: lang/private/teachprims
>
I've opened the .local/share/racket/8.2/pkgs/rsound/rsound/network.rkt file, and removed this part at line 6:
(only-in lang/private/teachprims beginner-<=)
and now it works...
on OS X El Capitan, after I call (play ding)
I get the following warning:
2016-05-07 10:55:29.298 racket[11763:764945] 10:55:29.298 WARNING: 140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
"played sound"
A call to pstream-play
returns "sound is queued",
but the documentation says that the pstream is to be returned.
error message refers to envelopes, not to synth-note
I found that (play/s ) will not play after it was used once & (stop) has been invoked. E.g:
(play/s ding) ; works
(stop)
(play/s ding) ; doesn't work
I'm using the current master of RSound as a development link in planet,
with Racket v5.3.4,
on Mac OS 10.6.8
They are provided by rsound and frequently used...
I think that a bunch of things will get cleaner if all playing is associated with pstreams. Starting & stopping signal-playing, sounds, etc.
the network
macro does not play nice with indexed-signal
:
(define test/not-ok
(network ()
[out2 (indexed-signal (lambda (f) 0))]))
(define test/ok
(let ([what (indexed-signal (lambda (f) 0))])
(network ()
[out2 (what)])))
play-signal
of test/not-ok
results in a contract violation for *
:
*: contract violation
expected: number?
given: #<network/s>
argument position: 2nd
other arguments...:
32767.0
Replace fader by fade-in and fade-out. Of course, we can reverse a fader but...
-jpr
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.