Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#76641 - 01/03/2002 00:10 Audio programing
peterk
journeyman

Registered: 28/11/2001
Posts: 87
Loc: California (Ex NZ)
Hi
It seems that the interface to /dev/audio has changed, putting sample code like pcmplay.c out of date.

I have been trying to compile a new version of pcmplay, based on references found in posts by Tony and Kim, however I haven't quite got it right.

I have commented out the references to ioctl(fd, SNDCTL_DSP_SETFMT etc as these cause run time errors. I understand they are no longer required.

I ahve also included commands to turn off the soft audio mute and set the source to PCM.

I have created a PCM file, and am trying to play it using ./pcmplay < file.pcm

It seems to be doing something, as it is several seconds before the cursor comes back, however I get no sound

I have compiled beep.c (makes a beep using the DSP) and this works correctly, so I am cautiously confident with my new dev environment.

printf debugging shows that all the appropriate parts of the code are being reached, I'm simply getting no sound.

I'm alternating between hijack 200 and hijack 200 with the Kims sound overlay patch.


My source is below. If anyone can comment on what I am doing wrong I would really appreciate it.

When this is resolved, I'll send the source to Tony, so he can update the FAQ.

Cheers
Peter Kerr

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

#include <sys/ioctl.h>
#include <sys/soundcard.h>

#include <stdlib.h>


# define AUDIO_DEVICE "/dev/audio"
# define AUDIO_FILLSZ 4608

int iAudio;
int iMixer;
int iSource = SOUND_MASK_PCM;
int iFlags = 0; // source not muted
int iSAM = 0; // SAM is off
int iVolume = 100|(100 << 8);

static
int output(int fd, void const *buf, unsigned int len)
{
char const *ptr = buf;
int wrote;

while (len) {
wrote = write(fd, ptr, len);
if (wrote == -1) {
if (errno == EINTR)
continue;
else
return -1;
}

ptr += wrote;
len -= wrote;
}

return 0;
}

static
int audio_buffer(int fd, void const *buf, unsigned int len)
{
char const *ptr = buf;
static char hold[AUDIO_FILLSZ];
static unsigned int held;
unsigned int left, grab;

if (len == 0) {
if (held) {
memset(&hold[held], 0, &hold[AUDIO_FILLSZ] - &hold[held]);
held = 0;
return output(fd, hold, AUDIO_FILLSZ);
}

return 0;
}

if (held == 0 && len == AUDIO_FILLSZ)
return output(fd, ptr, len);

left = AUDIO_FILLSZ - held;

while (len) {
grab = len < left ? len : left;

memcpy(&hold[held], ptr, grab);
held += grab;
left -= grab;

ptr += grab;
len -= grab;

if (left == 0) {
if (output(fd, hold, AUDIO_FILLSZ) == -1)
return -1;

held = 0;
left = AUDIO_FILLSZ;
}
}

return 0;
}

# define audio_flush(fd) audio_buffer((fd), 0, 0)

static
int audio_init(int fd)
{
int format, stereo, speed;
//
// format = AFMT_S16_LE;
// if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1) {
// perror("ioctl(SNDCTL_DSP_SETFMT)");
// return -1;
// }
// if (format != AFMT_S16_LE) {
// fprintf(stderr, "AFMT_S16_LE not available
//");
// return -1;
// }

// stereo = 1;
// if (ioctl(fd, SNDCTL_DSP_STEREO, &stereo) == -1) {
// perror("ioctl(SNDCTL_DSP_STEREO)");
// return -1;
// }
// if (!stereo) {
// fprintf(stderr, "stereo selection failed");
// return -1;
// }

// speed = 44100;
// if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) == -1) {
// perror("ioctl(SNDCTL_DSP_SPEED)");
// return -1;
// }
// if (speed != 44100) {
// fprintf(stderr, "sample speed 44100 not available (closest %u)
//", speed);
// return -1;
// }

return 0;
}

int main(int argc, char *argv[])
{
static char buffer[AUDIO_FILLSZ];
int fd;
unsigned int len;

fd = open(AUDIO_DEVICE, O_WRONLY);
if (fd == -1) {
perror(AUDIO_DEVICE);
return 1;
}

if (audio_init(fd) == -1) {
close(fd);
return 2;
}
iMixer = open("/dev/mixer",O_RDONLY);
ioctl(iMixer,_IOW('m',0,int),&iSource); // set source
ioctl(iMixer,_IOW('m',1,int),&iFlags); // set Flags
ioctl(iMixer,_IOW('m',15,int),iSAM); // set Soft Audio Mute
ioctl(iMixer,MIXER_WRITE(SOUND_MIXER_VOLUME), &iVolume);

while ((len = fread(buffer, 4, AUDIO_FILLSZ / 4, stdin))) {
if (audio_buffer(fd, buffer, 4 * len) == -1) {
perror("write");
return 3;
}
}

if (ferror(stdin)) {
perror("read");
return 4;
}

if (audio_flush(fd) == -1) {
perror("write");
return 3;
}

if (close(fd) == -1) {
perror("close");
return 5;
}
close(iMixer);
printf("Done\n");
return 0;
}


Top
#76642 - 21/03/2002 19:08 Re: Audio programing [Re: peterk]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
I'm going to ressurrect this archived post because I'm trying to do the exact same thing. I'm trying to get my empeg to play a startup sound during bootup. To do this I need a program that can be called from my init script to play an audio file. This pcmplay (from http://www.empeg.mars.org/devel/hardware/audio.php3 ) program would be perfect, if only it worked. Could any of the experienced programmers out there see if they could get this program working again? Thank you.

Top
#76643 - 21/03/2002 21:03 Re: Audio programing [Re: DomoKun]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
This modified source works for me. I haven't used it with the overlay patch or anything like that though.

- Trevor


Attachments
80891-pcmplay.c (170 downloads)


Top
#76644 - 21/03/2002 22:00 Re: Audio programing [Re: tman]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
Could you please post the compiled version of this also? I'm pretty new to both linux and c++ so I must be doing something wrong.

Top
#76645 - 21/03/2002 22:13 Re: Audio programing [Re: DomoKun]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
Here you go.

Upload it and remember to make it executable (chmod 700 pcmplay)

- Trevor


Attachments
80919-pcmplay (186 downloads)


Top
#76646 - 22/03/2002 08:06 Re: Audio programing [Re: tman]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
that liddle proggy works good! but u need a special kind of pcm file.. i got the win notify tone work.. hum.. ill try to convert some files to the right form!

what scripts do i need to modify to start it at boot? cant i simple use the hijack execute feature in config.ini?

Top
#76647 - 22/03/2002 08:33 Re: Audio programing [Re: Draghtnod]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
here's a working converted pcm-file.. seems the klick at the beginning of every pcm file comes from the player..


Attachments
80969-bootsound.pcm (182 downloads)


Top
#76648 - 22/03/2002 12:58 Re: Audio programing [Re: tman]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
I must be doing something stupid. I've copied the file onto unit, and I did "chmod 700 pcmplay" to give it permission like you said. However when I try to run it, it freezes the empeg. I've used the program cool edit to convert my WAV files to RAW PCM in 16-bit stereo 44100k. Am I incorrectly running the program? While I'm in the folder where I saved pcmplay I type:
./pcmplay /drive0/startupsounds/sound1.pcm
It just locks up after this and I hear no sound.

Top
#76649 - 22/03/2002 13:03 Re: Audio programing [Re: Draghtnod]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
I started making a custom init file that would play a startup sound. Once I actually get this to play something I'll post my completed init file here. You can follow this thread http://empeg.comms.net/php/showflat.php?Cat=&Board=empeg_general&Number=78613&page=&view=&sb=&o=&vc=1 for information on how I created the custom init.

Top
#76650 - 22/03/2002 13:25 Re: Audio programing [Re: DomoKun]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
you start pcmplay wrong!
try that:
./pcmfile < soud.pcm
it freeses if you type something wrong or forget that "<"
and you can "defreese" or abort every comandline program with ctrl+C

letz see if i get that inithing up to work =)

Top
#76651 - 22/03/2002 18:14 Re: Audio programing [Re: Draghtnod]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
Thanks. Everything works great. I now have start up sounds. This is my init script which is programmed to choose 1 out of 12 random startup sounds:

#!/bin/sh
PATH=.:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/empeg/bin
PS1=empeg:\\w\\$
/bin/mount -n -o nocheck,rw /proc
/bin/mount -n -o nocheck,ro /dev/hda4 /drive0
/bin/mount -n -o nocheck,ro /dev/hdc4 /drive1

#choose a random number 0 through 11
RANGE=12
number=$RANDOM
let "number %= $RANGE"

#play a random startup sound
echo Playing random startup sound
cd /drive0/var
if [ $number -eq 0 ]
then
./pcmplay < /drive0/startup/welcome.pcm
elif [ $number -eq 1 ]
then
./pcmplay < /drive0/startup/train.pcm
elif [ $number -eq 2 ]
then
./pcmplay < /drive0/startup/shortcircuit.pcm
elif [ $number -eq 3 ]
then
./pcmplay < /drive0/startup/playgame.pcm
elif [ $number -eq 4 ]
then
./pcmplay < /drive0/startup/lionroar.pcm
elif [ $number -eq 5 ]
then
./pcmplay < /drive0/startup/jet.pcm
elif [ $number -eq 6 ]
then
./pcmplay < /drive0/startup/horse.pcm
elif [ $number -eq 7 ]
then
./pcmplay < /drive0/startup/homeranykey.pcm
elif [ $number -eq 8 ]
then
./pcmplay < /drive0/startup/homer7dohs.pcm
elif [ $number -eq 9 ]
then
./pcmplay < /drive0/startup/hal9000.pcm
elif [ $number -eq 10 ]
then
./pcmplay < /drive0/startup/butthead.pcm
elif [ $number -eq 11 ]
then
./pcmplay < /drive0/startup/airbreak.pcm
fi

while [ 1 ] ; do
echo "Press q now to terminate to a shell prompt."
echo
/drive0/var/getkey q && /bin/bash
echo Running Player...
/empeg/bin/player
done

Top
#76652 - 22/03/2002 18:33 Re: Audio programing [Re: DomoKun]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
The case command is your friend:
case "$number" in

'1')
play 1
;;
'2')
play 2
;;
*)
play default
;;
esac
_________________________
Bitt Faulk

Top
#76653 - 23/03/2002 02:42 Re: Audio programing [Re: DomoKun]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
where do i insert the command for that script itself?

Top
#76654 - 23/03/2002 03:02 Re: Audio programing [Re: Draghtnod]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
oh.. i have to replace the /bin/init script!
well.. uhm.. jo!

Top
#76655 - 23/03/2002 03:34 Re: Audio programing [Re: Draghtnod]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
content of the new init file:

#!/bin/sh
PATH=.:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/empeg/bin
PS1=empeg:\\w\\$
/bin/mount -n -o nocheck,rw /proc
/bin/mount -n -o nocheck,ro /dev/hda4 /drive0
/bin/mount -n -o nocheck,ro /dev/hdc4 /drive1

#choose a random number and set range
number=$RANDOM
let "number %= 2"

#play a random startup sound
echo Playing random startup sound $number
case "$number" in
'0')
/pcmplay < /f1
;;
'1')
/pcmplay < /f2
;;
esac

while [ 1 ] ; do
echo "Press q now to terminate to a shell prompt."
echo
/drive0/var/getkey q && /bin/bash
echo Running Player...
/empeg/bin/player
done



what i had done:

i had copy that init to /bin namend init.new
cd /bin
mv init init.old
mv init.new init
chmod 755 init
exit



and the next reboot says that:

empeg-car bootstrap v1.02 20001106 ([email protected])
If there is anyone present who wants to upgrade the flash, let them speak now,
or forever hold their peace...it seems not. Let fly the Penguins of Linux!

e000 v1.04
Copying kernel...
Calling linux kernel...
Uncompressing Linux...................................... done, booting the kern
el.
Linux version 2.2.14-rmk5-np17-empeg50-hijack-v246 ([email protected]) (gcc ve
rsion 2.95.3 20010315 (release)) #2 Mon Mar 18 10:32:16 EST 2002
Processor: Intel StrongARM-1100 revision 11
NetWinder Floating Point Emulator V0.94.1 (c) 1998 Corel Computer Corp.
empeg-car player (hardware revision 9, serial number 30102610)
Command line: mem=16m
Calibrating delay loop... 207.67 BogoMIPS
Memory: 14984k/16M available (1012k code, 20k reserved, 364k data, 4k init)
Dentry hash table entries: 2048 (order 2, 16k)
Buffer cache hash table entries: 16384 (order 4, 64k)
Page cache hash table entries: 4096 (order 2, 16k)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.2
Based upon Swansea University Computer Society NET3.039
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
TCP: Hash tables configured (ehash 16384 bhash 16384)
IrDA (tm) Protocols for Linux-2.2 (Dag Brattli)
Linux-IrDA: IrCOMM protocol ( revision:Tue May 18 03:11:39 1999 )
ircomm_tty: virtual tty driver for IrCOMM ( revision:Wed May 26 00:49:11 1999 )
Starting kswapd v 1.5
SA1100 serial driver version 4.27 with no serial options enabled
ttyS00 at 0xf8010000 (irq = 15) is a SA1100 UART
ttyS01 at 0xf8050000 (irq = 17) is a SA1100 UART
ttyS02 at 0xf8030000 (irq = 16) is a SA1100 UART
Signature is 20706d65 'emp '
Found custom animation at offset 0x98f84
empeg display initialised.
empeg dsp audio initialised
empeg dsp mixer initialised
empeg dsp initialised
empeg audio-in initialised, CS4231A revision a0
empeg remote control/panel button initialised.
empeg usb initialised, PDIUSBD12 id 1012
empeg state support initialised 0089/88c1 (save to d0004480).
empeg RDS driver initialised
empeg power-pic driver initialised
RAM disk driver initialized: 16 RAM disks of 4096K size
empeg single channel IDE
Probing primary interface...
hda: IBM-DJSA-210, ATA DISK drive
hda: IBM-DJSA-210, ATA DISK drive
hda: IBM-DJSA-210, ATA DISK drive
hda: IBM-DJSA-210, ATA DISK drive
hda: IBM-DJSA-210, ATA DISK drive
hda: IBM-DJSA-210, ATA DISK drive
ide0 at 0x000-0x007,0x038 on irq 6
hda: IBM-DJSA-210, 9590MB w/384kB Cache, CHS=19485/16/63
empeg-flash driver initialized
smc chip id/revision 0x3349
smc9194.c:v0.12 03/06/96 by Erik Stahlman ([email protected])

SMC9194: SMC91C94(r:9) at 0x4008000 IRQ:7 INTF:TP MEM:6144b MAC 00:02:d7:26:0a:3
2
Partition check:
hda: hda1 < hda5 hda6 > hda2 hda3 hda4
RAMDISK: ext2 filesystem found at block 0
RAMDISK: Loading 320 blocks [1 disk] into ram disk... done.
VFS: Mounted root (ext2 filesystem).
empeg-pump v0.03 (19980601)
Press Ctrl-A to enter pump...VFS: Mounted root (ext2 filesystem) readonly.
change_root: old root has d_count=1
Trying to unmount old root ... okay
Freeing unused kernel memory: 4k init
: No such file or directory

..and the player hangs up! no chance to get into bash..
what the hack had i done wrong?!?

Top
#76656 - 23/03/2002 03:39 Re: Audio programing [Re: Draghtnod]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
by the way.. how can i mount that root partition on my linux system? isnt it in the flash? or how do i fix that?

thanks..

Top
#76657 - 23/03/2002 08:24 Re: Audio programing [Re: Draghtnod]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
Do you have the file /drive0/var/getkey loaded on your system? I got that program from the picker package that was posted on that other thread i mentioned in an earlier post. Be sure to load that and give it proper permissions. I think you will probably have to reflash the player software to be able to get back to bash.

Top
#76658 - 23/03/2002 09:15 Re: Audio programing [Re: DomoKun]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
and make sure to add quit=1 to your config.ini

Top
#76659 - 23/03/2002 14:03 Re: Audio programing [Re: DomoKun]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
okay!
i uploaded the 2b11-develloper, hijack 246, pcmplay, getkey, audiofiles, new init, config.ini with quit=1
then i chmod everything right, reboot and....

...now i have to do all that again! it hangs up..
dont know where that bug is but ill get it!


Edited by Draghtnod (23/03/2002 14:05)

Top
#76660 - 23/03/2002 14:22 Re: Audio programing [Re: Draghtnod]
mtempsch
pooh-bah

Registered: 02/06/2000
Posts: 1996
Loc: Gothenburg, Sweden
Check what it says on the serial output... it generally gives a fair clue as to what goes wrong.

/Michael
_________________________
/Michael

Top
#76661 - 23/03/2002 14:34 Re: Audio programing [Re: mtempsch]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
:No such file or directory

domokun could you please post your init script? if i start it manually from bash it says:

:No such file or directory

Top
#76662 - 23/03/2002 14:52 Re: Audio programing [Re: Draghtnod]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
empeg:/empeg# ls -l
total 3
drwxr-xr-x 2 0 0 1024 Feb 8 18:47 bin
lrwxrwxrwx 1 0 220 14 Feb 8 18:47 fids0 -> ../drive0/fids
lrwxrwxrwx 1 0 220 14 Feb 8 18:47 fids1 -> ../drive1/fids
-rwxr-xr-x 1 0 0 728 Mar 23 21:47 init
drwxr-xr-x 6 0 0 1024 Feb 8 18:47 lib
lrwxrwxrwx 1 0 220 13 Feb 8 18:47 var -> ../drive0/var
empeg:/empeg# cat ./init
#!/bin/sh
echo starting
PATH=.:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/empeg/bin
PS1=empeg:\\w\\$
/bin/mount -n -o nocheck,rw /proc
/bin/mount -n -o nocheck,ro /dev/hda4 /drive0
/bin/mount -n -o nocheck,ro /dev/hdc4 /drive1
echo mount
#choose a random number 0 through 11
RANGE=2
number=$RANDOM
let "number %= $RANGE"

#play a random startup sound
echo Playing random startup sound
cd /drive0/var/bootsound
if [ $number -eq 0 ]
then
./pcmplay < f1
elif [ $number -eq 1 ]
then
./pcmplay < f2
fi

while [ 1 ] ; do
echo "Press q now to terminate to a shell prompt."
echo
/drive0/var/getkey q && /bin/bash
echo Running Player...
/empeg/bin/player
done
empeg:/empeg# ./init
: No such file or directory
empeg:/empeg# sh ./init
starting
: command not found
: command not found
mount: you must specify the filesystem type
Usage: mount [-hV]
mount -a [-nfFrsvw] [-t vfstypes]
mount [-nfrsvw] [-o options] special | node
mount [-nfrsvw] [-t vfstype] [-o options] special node
A special device can be indicated by -L label or -U uuid .
Usage: mount [-hV]
mount -a [-nfFrsvw] [-t vfstypes]
mount [-nfrsvw] [-o options] special | node
mount [-nfrsvw] [-t vfstype] [-o options] special node
A special device can be indicated by -L label or -U uuid .
mount
: command not found
: command not found
./init: let: number %= : syntax error: operand expected (error token is " ")
: command not found
Playing random startup sound
'/init: line 23: syntax error near unexpected token `
'/init: line 23: `fi
empeg:/empeg# anybody see the problem? all files in the init are there and working

Top
#76663 - 23/03/2002 17:13 Re: Audio programing [Re: Draghtnod]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
Attached to this message is my init file. It works really nicely. There was an error in the previous init file I posted. I changed the directory to my /drive0/startup folder and never changed back to the root. This prevented emplode from working. So I just changed it to run the pcmplay program without using a cd command.


Attachments
81290-init (156 downloads)


Top
#76664 - 24/03/2002 00:50 Re: Audio programing [Re: Draghtnod]
mtempsch
pooh-bah

Registered: 02/06/2000
Posts: 1996
Loc: Gothenburg, Sweden
It could be that you're suffering from the trailing carriage return syndrom.

If you created the file on a windows machine and uploaded to the empeg without passing it through an editor capable of saving it in Unix format (linefeed only as line termination, while Windows uses carriage return + linefeed)
That causes the empeg to try to pass on the script not to /bin/sh, but to the non-existing /bin/sh^M (^M=ASCII char 13=carriage return)

If that's not the case then I'd be suspicious of the
cd /drive0/var/bootsound
./pcmplay

Is your pcmplay file in /drive0/var/bootsound?


/Michael
_________________________
/Michael

Top
#76665 - 24/03/2002 04:43 Re: Audio programing [Re: mtempsch]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
yes i put all that bootsound files to /drive0/var/bootound..

hum.. ill try to edit this file on my linux system and upload it then! windows suxx realy in every case!

Top
#76666 - 24/03/2002 07:07 Re: Audio programing [Re: Draghtnod]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
yeah that was it!

i have made a lot of changes now.. it makes all a liddl bit more handy! but my player plays no sounde before the real player was startet..
it starts normal,
makes my scripts and does the pcmplay correct without errors,
and start the player..

all without any errors.. if i go to bash and run the bootsound script again (like on start), it plays that random sound...

anybody knows whay domokuns script works and mine not? *lol*

Top
#76667 - 07/04/2002 17:33 Re: Audio programing [Re: Draghtnod]
DomoKun
journeyman

Registered: 14/03/2002
Posts: 94
Loc: Pennsylvania
I've been running with my startup sounds for a couple of weeks now and I really think it is great. I have been running it with hijack 246. However today I decided to upgrade to hijack 253 and the startup sounds stopped working. I'm not sure which update between 247 and 253 caused it to stop working, but one of them did. I downgraded back to 246 and everything is working again.

So Draughtnod, if you still want to get this to work on yours I would try loading hijack 246. And if Mark comes back maybe I can convince him to fix whatever went wrong?

Top
#76668 - 08/04/2002 05:32 Re: Audio programing [Re: DomoKun]
Draghtnod
journeyman

Registered: 03/02/2002
Posts: 71
oh i gave up weaks ago.. i didnt know that the hijack caused this problem! but thanks at all

Top