Skip to contentSkip to conversation

mpg123 hack

PATCH Ulf Carlsson 2 participants 4 messages Apr 5, 1999 – Apr 6, 1999 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I know this is silly and you don't care about it, but I've patched mpg123 so that I can play mp3's without generating wav files in between :-). Maybe you say that I should fix my poor HAL2 driver instead - I will...

About the noise:

I have done some testing with mpg123. The HAL2 is, to say the least, acting weird. I found that only every other sample is played, and the other ones are dumped.

Ok now to the really really weird part: If I play audio on the samples which are dumped and zeros on the ones which are played I can hear this silly noise in the speakers. If I do not play anything, zeros in both channels, it's death quiet (although the DMA is acting and the HAL2 is playing the zeros). If I play zeros on the dumped channel and audio on the other one I can hear this noise again.

Hum, I have been looking at this noise problem for nearly two days now without any progress. Testing one thing the other with no effect. Quite boring, I'll hack something else tomorrow..

- Ulf

Makefile +12 -1
diff -ur mpg123-0.59q-orig/Makefile mpg123-0.59q/Makefile
@@ -56,7 +56,7 @@
 	@echo "make linux-nas      Linux, output to Network Audio System"
 	@echo "make linux-sparc    Linux/Sparc"
 	@echo "make linux-sajber   Linux, build binary for Sajber Jukebox frontend"
-	@echo "make linux-alsa     Linux with ALSA sound driver"
+	@echo "make linux-mips-alsa Linux/MIPS with ALSA sound driver"
 	@echo ""
 	@echo "make linux-esd      Linux, output to EsounD"
 	@echo "make linux-alpha-esd Linux/Alpha, output to EsounD"
@@ -148,6 +148,17 @@
 		CFLAGS='-DI386_ASSEM -DREAL_IS_FLOAT -DPENTIUM_OPT -DLINUX \
 			-DREAD_MMAP -DALSA \
 			-Wall \
+			-fomit-frame-pointer -funroll-all-loops \
+			-finline-functions -ffast-math \
+			$(RPM_OPT_FLAGS)' \
+		mpg123-make
+
+linux-mips-alsa:
+	$(MAKE) CC=gcc LDFLAGS= \
+		AUDIO_LIB='-lasound' \
+		OBJECTS='decode.o dct64.o audio_alsa.o' \
+		CFLAGS='-DLINUX -DREAD_MMAP -DSWAP_BYTES -DREAL_IS_FLOAT \
+			-DALSA -Wall -O2 \
 			-fomit-frame-pointer -funroll-all-loops \
 			-finline-functions -ffast-math \
 			$(RPM_OPT_FLAGS)' \
audio_alsa.c +16 -0
diff -ur mpg123-0.59q-orig/audio_alsa.c mpg123-0.59q/audio_alsa.c
@@ -182,8 +182,24 @@
 int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len)
 {
 	ssize_t ret;
+#ifdef SWAP_BYTES
+	int samples = len >> 1; /* will only work in 16 bit mode .. */
+	unsigned short *sample = (unsigned short *) buf;
+	static unsigned short *swap_buf = NULL;
 
+	if (!swap_buf)
+		swap_buf = (unsigned short *) malloc(len);
+
+	while (samples--) {
+		swap_buf[samples] =
+			(((sample[samples] & 0x00ff) << 8) |
+			((sample[samples] & 0xff00) >> 8));
+	}
+
+	ret=snd_pcm_write(ai->handle, swap_buf, len);
+#else
 	ret=snd_pcm_write(ai->handle, buf, len);
+#endif
 
 	return ret;
 }

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Charles,

Quoted 3 lines

Weird thought: what happens when you duplicate samples? (ie make the dumped samples the same as the ones which are played) It sounds like a common-mode rejection ratio problem

Whee!! That gives me PERFECT audio quality, well stereo and just 22050 Hz, but no noise. Can you explain to me what a common-mode rejection ratio problem is and why it's solved in this odd way?

Quoted 4 lines

You may find it helpful to patch the line-out jack from the Indy to the line-in on another system, and record it. If you can capture the noise with this arrangement, I'd be glad to take a look at it and see if there's any rhyme or reason to it.

Yeah, my noise is really exciting...

I'll try to find a decent cable so that I can record it.

Quoted 3 lines

I'd love to help directly (I have 3 Indys in the lab to play with) but I still can't get a system to boot properly, as I don't maintain any Linux/x86 boxes on that subnet.

I'd be more than happy to receive some help!

- Ulf

#3 lore raw
In reply to a message not in the archive

Hi again,

The problem seems to be that the HAL2 because of some strange reason I don't know requires the samples to be duplicated. There's no doubt about that the HAL2 is in stereo mode though, I print the registers every time the card is triggered. One might otherwise think that I accidently had set it up into Quad mode.

I can now play MP3 in 44100Hz, stereo with perfect audio quality, when the samples are duplicated..

- Ulf

#4 lore raw
Quoted 3 lines

is in stereo mode though, I print the registers every time the card is triggered. One might otherwise think that I accidently had set it up into Quad mode.

If you put the chip in mono mode does it need doubled samples ?