Hello!
After lots of experiments I got it working!
It plays audioCD right from /dev/disk1s* (change it in code to match your system), in raw format!
Has 3 awesome visualizers:
First, activated by pressing UP:
Second, activated with DOWN:
And third, activated with BACKSPACE:
You can switch next-prev tracks with left-right keys . Auto-switching is broken for now .
If anyone knows how to make this work on Windoze, please tell me
Code is here: https://github.com/vladkorotnev/my_pixi ... layer.pixi
Audio CD Player on Pixilang !
- vladkorotnev
- Posts: 6
- Joined: Thu Aug 16, 2012 7:38 pm
- Location: Ufa, Russia
- Contact:
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: Audio CD Player on Pixilang !
any chance i can get this to work for any wav file on my system? the screenshots look really cool
- vladkorotnev
- Posts: 6
- Joined: Thu Aug 16, 2012 7:38 pm
- Location: Ufa, Russia
- Contact:
Re: Audio CD Player on Pixilang !
I suppose you could, this seems to be just doing a raw read of the track data (it's been a long time since I wrote this! haha)
Substitute line 47: https://github.com/vladkorotnev/my_pixi ... r.pixi#L47
With something that will end up with your wav file in the `tp` variable as the first argument to `fopen`.
Sadly I don't remember much about Pixilang, so I don't know how to bring up a file picker or something.
Substitute line 47: https://github.com/vladkorotnev/my_pixi ... r.pixi#L47
With something that will end up with your wav file in the `tp` variable as the first argument to `fopen`.
Sadly I don't remember much about Pixilang, so I don't know how to bring up a file picker or something.
- AutumnCheney
- Posts: 507
- Joined: Sun Dec 29, 2019 8:16 am
- Location: tahlequah, ok, usa
- Contact:
Re: Audio CD Player on Pixilang !
hey, you're alive!
i tried importing the graphics code into a basic wav player based on nightradio's examples. i have a file called "100yrslp.wav" in the "sound_files" directory that i want to play.
the audio works, and the graphics do load and do respond to key inputs, but they don't seem to be doing anything. i think that it isn't importing the file, and i don't know how to get it to.
here's my code:
sorry about the bad formatting
i tried importing the graphics code into a basic wav player based on nightradio's examples. i have a file called "100yrslp.wav" in the "sound_files" directory that i want to play.
the audio works, and the graphics do load and do respond to key inputs, but they don't seem to be doing anything. i think that it isn't importing the file, and i don't know how to get it to.
here's my code:
Code: Select all
// WAV file player
// How to use: change the SETUP part and run this program to play the specified file
//
// ########################################
// ## SETUP ###############################
// ########################################
//Input WAV file:
filename = "examples/sound/sound_files/100yrslp.wav"
//Graphics options:
xsize = 1280
ysize = 720
//Sound options:
sample_rate_scale = 1
// ########################################
// ## SETUP COMPLETE ######################
// ########################################
if xsize == 0 { ss = 480 } else { ss = xsize }
set_pixel_size( WINDOW_XSIZE / ss )
resize( get_screen(), WINDOW_XSIZE, WINDOW_YSIZE )
scr = get_screen()
if xsize != 0 && ysize != 0 { resize( scr, xsize, ysize ) }
xsize = get_xsize( scr )
ysize = get_ysize( scr )
hxsize = xsize / 2
hysize = ysize / 2
traknum = 1
start_timer (0)
vis_num = 0
kR = 0
kG = 0
kB = 0
ktR = 70
ktG = 70
ktB = 100
xs = get_xsize ( get_screen() )
ys = get_ysize ( get_screen() )
hxs = xs / 2
hys = ys / 2
if fps == 0 { fps = 30 }
playtrak:
wav = load( filename )
tp = ""
sprintf (tp, filename)
f = fopen (tp, "rb") // Opens
portion = 2048 //FRAME SIZE
ffts = portion // FFT Size
buf = new ( portion, 1, INT16 ) //Buffer for read
clean (buf)
im = new( ffts, 1, FLOAT32 ) // Buffer for FFT
clean( im )
re = new( ffts, 1, FLOAT32 ) // Buffer for FFT
clean( re )
sb= new( ffts, 1, FLOAT32 ) // Buffer for VIS
clean( sb )
vis_num = 0 // Current VIS
logf( "WAV Sample Rate: %d\n", wav.sample_rate )
logf( "WAV Channels: %d\n", wav.channels )
wav_ptr = 0
wav_size = get_size( wav ) //number of frames
wav_channels = wav.channels
wav_amp_max = 256
type = get_type( wav )
if type == INT16 { wav_amp_max = 1 << 15 }
if type == INT32 { wav_amp_max = 1 << 30 }
if type == FLOAT32 { wav_amp_max = 1 }
rate1 = get_audio_sample_rate( 0 )
rate2 = get_audio_sample_rate( 1 )
logf( "Local (defined by the set_audio_callback()) sample rate: %d Hz\n", rate1 )
logf( "Global (defined in the global Pixilang preferences) sample rate: %d Hz\n", rate2 )
if rate1 != rate2
{
logf( "%d != %d, so resampling will be enabled\n", rate1, rate2 )
}
set_audio_callback( audio_callback, 0, wav.sample_rate * sample_rate_scale, get_type( wav ), wav_channels, AUDIO_FLAG_INTERP2 )
fn cv( $color ) // Cool Visual of $color
{
scr = get_screen()
xsize = get_xsize( scr )
ysize = get_ysize( scr )
hxsize = xsize/2
c = 0
x = -hxsize while( x < hxsize )
{
dot( x, buf[ hxsize+x ] / 1024, $color )
x + 1
}
} // End Cool Visual
fn cvR( $color , $rate ) // Cool Visual of $color at $rate
{
scr = get_screen()
xsize = get_xsize( scr )
ysize = get_ysize( scr )
hxsize = xsize/2
c = 0
x = -hxsize while( x < hxsize )
{
line(x, -buf[ hxsize+x ]/512, x, buf[ hxsize+x ]/512, $color)
x + $rate
}
}
fn render_vis_f() { // Renders Visual #2 (key DOWN)
transp( 150 ) // Transparency (fade) Effect
clear()
transp( 256 )
fft(0,im,re,portion) //FFT
inv = get_color(255-(2.55*kR),255-(2.55*kG),255-(2.55*kB))
// inverted color of kR/kG/kB
x = 0 while (x < xs) {
Y = sqrt ( im[x+50]*im[50+x] + re[50+x]*re[x+50] )
Y / 1000
line(x-hxs,-hys,x-hxs,-sb[x]/50,inv)
x + 1
}
effector( EFF_HBLUR, 64, WHITE, -hxs, -hys, xs, ys )
effector( EFF_VBLUR, 64, WHITE, -hxs, -hys, xs, ys )
x = 0 while (x < xs) {
Y = sqrt ( im[x]*im[x] + re[x]*re[x] )
Y / 1000
line(x-hxs,sb[x]/100,x-hxs,hys+Y,get_color(2.55 * kR,2.55 * kG,2.55 * kB))
x + 2
}
effector( EFF_VBLUR, 32, WHITE, -hxs, -hys, xs, ys )
} //END Visual 2
fn render_vis_w() { // Visual #1 (key UP)
transp(89) //Fade effect
clear()
transp(255)
if (sb[0]/1000 > 4) && (sb[0]/1000 < 1000) { //Thresholded BG 'lights'
x = -hxs
while (x<hxs) {
line(x,-sb[hxs+x]/100,x,sb[hxs+x]/100,get_color(kR*(sb[hxs+x]/10000),kG*(sb[hxs+x]/10000),kB*(sb[hxs+x]/10000)))
x + 1
}
effector(EFF_HBLUR,24)
effector(EFF_VBLUR,24)
}
x = -hxs
while (x<hxs) { // Graph, gradiented
dot(x,sb[hxs+x]/1000,get_color(kR*(abs(sb[hxs+x])/10000),kG*(abs(sb[hxs+x])/8000),kB*(abs(sb[hxs+x])/10000)))
x + 1
}
kR = rand() % 100 // New colors
kG = rand() % 100
kB = rand() % 100
}
fn render_vis_r() { // Visual #3 (key BACKSPACE)
t = get_timer( 0 )
transp( 50 )
clear()
transp( 255 )
cvR(ORANGE,4)
effector( EFF_VBLUR, 12 )
effector( EFF_HBLUR, 12 )
cv(GREEN)
print("vladkorotnev's CD player")
frame()
}
while (1) {
t = get_timer( 0 )
t = get_timer(0) // Vis Purposes
if vis_num == 0 { render_vis_w() } // Visual 1
if vis_num == 1 { render_vis_f() } // Visual 2
if vis_num == 2 { render_vis_r() } //Visual 3
while( get_event() ) { //Keys
if EVT[ EVT_TYPE ] == EVT_QUIT { halt } //Quit
if EVT[ EVT_KEY ] == KEY_LEFT {
fclose(f) //close file
traknum - 0.5 //prev num
go playtrak //play
// Not using GO because fires twice, lol
} // Left - Prev
if EVT[ EVT_KEY ] == KEY_RIGHT {
fclose(f) //close file
traknum + 0.5 //next num
go playtrak //play
// Not using GO because fires twice, lol
} //Right - Next
if EVT[ EVT_KEY ] == KEY_UP { vis_num = 0 } // Up - vis1
if EVT[ EVT_KEY ] == KEY_DOWN { vis_num = 1 }//Down -vis2
if EVT[ EVT_KEY ] == KEY_BACKSPACE { vis_num = 2 } //BKSP - Vis3
}
ts = "" //temp str
sprintf(ts,"CD TRACK: %u",traknum)
print(ts,0,-hys+50 ) // display track
frame() //render done
if (t / 100) - (t div 100) == 0 {
ktR = rand() % 100 // new colors once in a while
ktG = rand() % 100
ktB = rand() % 100
}
//animate color transition
if (ktR > kR) {
kR + 1
}
if (ktR < kR) {
kR - 1
}
if (ktG > kG) {
kG + 1
}
if (ktG < kG) {
kG - 1
}
if (ktB > kB) {
kB + 1
}
if (ktB < kB) {
kB - 1
}
clean(im) //clean buffer of FFT
t_reset()
while( get_event() ) { if EVT[ EVT_TYPE ] == EVT_QUIT { breakall } }
frame()
}
fn audio_callback(
$stream,
$userdata,
$channels,
$frames,
$output_time_in_system_ticks,
$in_channels,
$latency_in_frames )
{
if wav_ptr >= wav_size { ret( 0 ) }
$c = 0 while( $c < wav_channels )
{
copy( $channels[ $c ], wav, 0, wav_ptr + $c, $frames, 1, wav_channels )
$c + 1
}
wav_ptr + $frames * wav_channels
ret( 1 )
copy ( re, buf, 0,0,portion,1,1)
copy ( sb, buf, 0,0,portion,1,1)
ret( 1 )
}
- vladkorotnev
- Posts: 6
- Joined: Thu Aug 16, 2012 7:38 pm
- Location: Ufa, Russia
- Contact:
Re: Audio CD Player on Pixilang !
Replacing the
block with the following should get it kind of working, i think:
There will most likely be a slight click on the start, because it expects raw PCM data, not a WAV file — that click would be it going over the RIFF WAVE header part of it.
Btw, it looks like the other code in the same github repo from before is the code for those effects — and a wav file — but as separate programs. I don't have Pixilang here so not 100% sure.
https://github.com/vladkorotnev/my_pixi ... scope.pixi
https://github.com/vladkorotnev/my_pixi ... lizer.pixi
Code: Select all
playtrak:
tp = "" // temp string
sprintf(tp,"/dev/disk1s%u",traknum) // Opens /dev/disk1s<TRACK>, CHANGE FOR YOUR SYSTEM
f = fopen (tp,"rb") // Opens
Code: Select all
playtrak:
tp = "examples/sound/sound_files/100yrslp.wav"
f = fopen (tp,"rb") // Opens
Btw, it looks like the other code in the same github repo from before is the code for those effects — and a wav file — but as separate programs. I don't have Pixilang here so not 100% sure.
https://github.com/vladkorotnev/my_pixi ... scope.pixi
https://github.com/vladkorotnev/my_pixi ... lizer.pixi