LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-09-2004, 04:12 PM   #1
karlan
Member
 
Registered: Aug 2003
Location: San Francisco, California
Distribution: Slackware
Posts: 158

Rep: Reputation: 30
Lightbulb i386 Asm audio player :-D


Who would have a use for my audio player written pure assembly(Thanks to Karsten Scheibler). I will be adding mp3/vorbis filters(also written in assembly).
the compiled binary is 700Bytes right now, and only plays wavs.

I would like everyone to read the article written by Karsten Scheibler here. I will be writing the format conversions soon. It will be Format <-> Wav -> AudioPlayer, for now. This will also allow me to convert all audio files VERY quickly(if I get it right)
Code:
Command Run:
mpg123 -q -w /dev/stdout /home/noowner/mp3s/Song.mp3 | /home/karlan/desktop/asmAudio /dev/stdin

On my 2.6Ghz P4 with 1Gb mem, you may wonder why I care:
  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND

18496 karlan    16   0 10804 4496 10308 S     1.9  0.4   0:03   0 mpg123
18497 karlan    15   0    12   12     8 S     0.1  0.0   0:00   0 asmAudio
Code:
;****************************************************************************
;****************************************************************************
;*
;* Written by Karsten Scheibler, 2003-DEC-08
;* Edited for asm media player by Karlan Mitchell (2004-July-09)
;* Permission has been granted from original author to release this
;* file with the Lesser Gnu Publice Licesnse(LGPL)
;* Note: You will see this file constantly molested
;*
;****************************************************************************
;****************************************************************************





global _start


;****************************************************************************
;* some assign's
;****************************************************************************
%assign SYS_READ			3
%assign SYS_WRITE			4
%assign SYS_OPEN			5
%assign SYS_IOCTL			54

%assign O_RDONLY			0
%assign O_WRONLY			1
%assign O_RDWR				2

%assign SNDCTL_DSP_RESET		0x00005000
%assign SNDCTL_DSP_SPEED		0xc0045002
%assign SNDCTL_DSP_SETFMT		0xc0045005
%assign		AFMT_S16_LE		0x00000010
%assign SNDCTL_DSP_CHANNELS		0xc0045006


;****************************************************************************
;* data
;****************************************************************************
section .data
device:				        db	"/dev/dsp", 0
					align	4
audio_handle:				dd	0
audiof_handle:				dd	0
ioctl_table:				dd	SNDCTL_DSP_RESET, 0
					dd	SNDCTL_DSP_SPEED, 44100
					dd	SNDCTL_DSP_CHANNELS, 1
					dd	SNDCTL_DSP_SETFMT, AFMT_S16_LE

section .bss
					alignb	4
audio_data:				resw    1



;****************************************************************************
;* audio_start
;****************************************************************************
section .text
_start:

	;open a raw audio file
	;format should be 44.1 kHz, stereo, 16 Bit signed

	pop eax
	pop eax
	pop eax
	mov	 ebx, eax
	mov	dword ecx, O_RDONLY
	mov	dword eax, SYS_OPEN
	int	byte  0x80
	mov	dword ebx, eax
	test	dword eax, eax
	js near audio_error
	mov	dword [audiof_handle], eax

	;open the device

	mov	dword eax, SYS_OPEN
	mov	dword ebx, device
	mov	dword ecx, O_WRONLY
	int	byte  0x80
	test	dword eax, eax
	js near audio_error
	mov	dword [audio_handle], eax

	;set the options: 44.1 kHz, mono, 16 Bit signed

do_ioctl:
	mov	dword eax, SYS_IOCTL
	mov	dword ebx, [audio_handle]
	mov	dword ecx, [ioctl_table + 8 * ebp]
	lea	dword edx, [ioctl_table + 8 * ebp + 4]
	int	byte  0x80
	test	dword eax, eax
	js	near  audio_error
	inc	dword ebp
	cmp	dword ebp, byte 4
	jb	short do_ioctl

	;set output to stereo

	lea	dword ebp, [ioctl_table + 4 * 6]
	mov	dword eax, SYS_IOCTL
	mov	dword ebx, [audio_handle]
	mov	dword ecx, SNDCTL_DSP_CHANNELS
	mov	dword [ebp], 2
	mov	dword edx, ebp
	int	byte  0x80
	test	dword eax, eax
	js	short audio_error

readnoutLoop:
	mov	dword eax, SYS_READ
	mov	dword ebx, [audiof_handle]
	mov	dword ecx, audio_data
	mov	dword edx, 2048
	int	byte  0x80
	cmp   eax,0
	je	short audio_end

	;dump it to the audio device
	mov     dword eax, SYS_WRITE
	mov	dword ebx, [audio_handle]
	mov	dword ecx, audio_data
	mov	dword edx, 2048
	int	byte  0x80
	;exit nicely
	jmp   short readnoutLoop




;****************************************************************************
;* audio_error
;****************************************************************************
audio_error:
	xor	dword eax, eax
	inc	dword eax
	mov	dword ebx, eax
	int	byte  0x80



;****************************************************************************
;* audio_end
;****************************************************************************
audio_end:
        ;we SHOULD close both files here......i'll get to it
	xor	dword eax, eax
	xor	dword ebx, ebx
	inc	dword eax
	int	byte  0x80
;***********************************************

Last edited by karlan; 07-09-2004 at 04:20 PM.
 
Old 07-10-2004, 12:36 PM   #2
hq4ever
Member
 
Registered: May 2004
Location: Israel
Distribution: Debian
Posts: 98

Rep: Reputation: 15
man you rock you know this!

good job, i don't know Assembly in that level to estimate your code but i can see the effort invested in it.

success is the only option :-)
 
Old 07-11-2004, 09:26 PM   #3
karlan
Member
 
Registered: Aug 2003
Location: San Francisco, California
Distribution: Slackware
Posts: 158

Original Poster
Rep: Reputation: 30
I need as much documentation as possible on mp3 compression schemes, can anyone help here?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
audio player JulienPDX Mandriva 4 03-26-2005 02:39 AM
Is there an audio player with content library like Media Player? Merlin53 Linux - Software 4 11-24-2004 06:42 PM
Audio CD Player nathan_newmai Linux - Software 1 07-25-2004 04:17 AM
What's the best audio player? teyesahr Linux - Software 6 04-14-2004 01:12 PM
no audio with CD player? LinuxCrusader Linux - Software 5 02-18-2004 09:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration