All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] SBC Decoder with /dev/dsp
@ 2005-05-01 12:43 Mayank Batra
  2005-05-01 12:57 ` Marcel Holtmann
  2005-05-01 15:21 ` Henryk Plötz
  0 siblings, 2 replies; 16+ messages in thread
From: Mayank Batra @ 2005-05-01 12:43 UTC (permalink / raw)
  To: BLUEZ DEVELOPERS LIST

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

Marcel,

This is the improved version for the sbcdec.c file
which you asked for.

It uses /dev/dsp to play the decoded samples.

The output is pretty well if we incorporate the proper
endian type.

I suggest that you keep it as a separate file incase
someone wants to use the AO Libraries.

Thanks and Regards,

Mayank. 

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

[-- Attachment #2: 1799107703-sbcdec.c --]
[-- Type: application/octet-stream, Size: 4450 bytes --]

/*
 *
 *  Bluetooth low-complexity, subband codec (SBC) decoder
 *
 *  Copyright (C) 2004  Marcel Holtmann <marcel@holtmann.org>
 *  Copyright (C) 2005  Mayank Batra <mayankbatra@yahoo.co.in>
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <sys/stat.h>
#include <sys/soundcard.h>

#include "sbc.h"

#define BUF_SIZE 4096

static void decode(char *filename)
{
	unsigned char *stream;
	struct stat st;
	off_t filesize;
	sbc_t sbc;
	int fd, id, pos, streamlen, framelen;
	int format=AFMT_S16_LE;
	int audio_fd;
	unsigned char audio_buffer[BUF_SIZE];
	int count=0;

	if (stat(filename, &st) < 0) {
		fprintf(stderr, "Can't get size of file %s: %s\n",
						filename, strerror(errno));
		return;
	}

	filesize = st.st_size;
	stream = malloc(st.st_size);

	if (!stream) {
		fprintf(stderr, "Can't allocate memory for %s: %s\n",
						filename, strerror(errno));
		return;
	}

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "Can't open file %s: %s\n",
						filename, strerror(errno));
		goto free;
	}

	if (read(fd, stream, st.st_size) != st.st_size) {
		fprintf(stderr, "Can't read content of %s: %s\n",
						filename, strerror(errno));
		close(fd);
		goto free;
	}

	close(fd);

	pos = 0;
	streamlen = st.st_size;
	sbc_init(&sbc, SBC_NULL);
	framelen = sbc_decode(&sbc, stream, streamlen);
	printf("%d Hz, %d channels\n", sbc.rate, sbc.channels);	

	/* Open the audio device */
	if((audio_fd=open("/dev/dsp",O_WRONLY,0))==-1) {
		printf("\nCan't open the audio device\n");
		exit(1);
	}

	/* Set the Format to be used */
	if(ioctl(audio_fd,SNDCTL_DSP_SETFMT,&format)==-1) {
		perror("\nSNDCTL_DSP_SETFMT\n");
		exit(1);
	}

	/* Set the number of channels */
	if(ioctl(audio_fd,SNDCTL_DSP_CHANNELS,&sbc.channels)==-1) {
		perror("\nSNDCTL_DSP_CHANNELS\n");
		exit(1);
	}

	/* Set the speed */
	if(ioctl(audio_fd,SNDCTL_DSP_SPEED,&sbc.rate)==-1) {
		perror("\nSNDCTL_DSP_SPEED\n");
		exit(1);
	}

	while (framelen > 0) {
		/* Do not straight away write sbc.data to device,
		instead, wait for a sufficient number of samples */
		memcpy(audio_buffer+count, sbc.data, sbc.len);
		count += sbc.len;
		if(count == 4096) {
			/* Now write to the device */
			write(audio_fd, audio_buffer, BUF_SIZE);
			count = 0;
		}
		pos += framelen;
		framelen = sbc_decode(&sbc, stream + pos, streamlen - pos);		
	}

	/* Decoding over, close the audio device */
	if(close(audio_fd)<0) {
		perror("\nUnable to close the audio device");
		exit(1);
	}

	sbc_finish(&sbc);

free:
	free(stream);
}

static void usage(void)
{
	printf("SBC decoder utility ver %s\n", VERSION);
	printf("Copyright (c) 2004  Marcel Holtmann\n\n");
	printf("Copyright (c) 2005  Mayank Batra\n\n");

	printf("Usage:\n"
		"\tsbcdec [options] file(s)\n"
		"\n");

	printf("Options:\n"
		"\t-h, --help           Display help\n"
		"\t-v, --verbose        Verbose mode\n"
		"\n");
}

static struct option main_options[] = {
	{ "help",	0, 0, 'h' },
	{ "verbose",	0, 0, 'v' },
	{ 0, 0, 0, 0 }
};

int main(int argc, char *argv[])
{
	int i, opt, verbose = 0;

	while ((opt = getopt_long(argc, argv, "+hv", main_options, NULL)) != -1) {
		switch(opt) {
		case 'h':
			usage();
			exit(0);

		case 'v':
			verbose = 1;
			break;

		default:
			exit(1);
		}
	}

	argc -= optind;
	argv += optind;
	optind = 0;

	if (argc < 1) {
		usage();
		exit(1);
	}

	for (i = 0; i < argc; i++)
		decode(argv[i]);

	return 0;
}

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [Bluez-devel] SBC Decoder with /dev/dsp
@ 2005-05-03 13:03 Mayank Batra
  0 siblings, 0 replies; 16+ messages in thread
From: Mayank Batra @ 2005-05-03 13:03 UTC (permalink / raw)
  To: bluez-devel

Brad,

> Is a2snk working now then? Can I factor out the
> common stuff in 
> a2snk/a2play without messing up changes anyone is
> holding onto?

Thanks for creating a2dp.h file

And yes, now it is final that a2snk (now a2recv) is
functioning.

I have tested it by using a2play as well as BlueSoleil
as the source. And it is working perfectly alright.

But the problem is again the sequential nature of
a2recv as Marcel pointed out.

But one thing:
a2recv functions in the following scenario:

1) I use a PCM file (.snd), encoded in little-endian
format.

2) I use a2play, which encodes it into sbc.

3) I decode the sbc stream with a2recv, open my
soundcard in little-endian format (My soundcard does
not support big-endian format). But for this I have to
patch the sbc.c to produce output in little endian
format.

After the above steps output is crystal clear.
And when I say clear, it means absolutely clear.
 
> Any suggestions for the name of the new header file
> that a2snk/a2play 
> will include? avdtp.h seems like a poor choice...

a2dp.h is great.
 

Mayank

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [Bluez-devel] SBC Decoder with /dev/dsp
@ 2005-05-03 13:12 Mayank Batra
  2005-05-03 15:36 ` Marcel Holtmann
  0 siblings, 1 reply; 16+ messages in thread
From: Mayank Batra @ 2005-05-03 13:12 UTC (permalink / raw)
  To: bluez-devel

Marcel,

> I had to change a lot more and so I started over.
> Please take a look at
> the end result in the CVS.

I saw the end result, it is ok, just i was missing my
name somewhere. :-)

Regards,

Mayank

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [Bluez-devel] SBC Decoder with /dev/dsp
@ 2005-05-08 13:17 Mayank Batra
  0 siblings, 0 replies; 16+ messages in thread
From: Mayank Batra @ 2005-05-08 13:17 UTC (permalink / raw)
  To: bluez-devel

Marcel,

> > > I had to change a lot more and so I started
> over.
> > > Please take a look at
> > > the end result in the CVS.
> > 
> > I saw the end result, it is ok, just i was missing
> my
> > name somewhere. :-)
> 
> that is because I don't copied your file. Instead I
> changed all the
> parts by hand and missed your changes for adding
> your name. Sorry for
> that. Better send diffs next time.

I'll do that in the future.

Is it possible to make the change now?

Sorry for bothering you, I know you are a busy man.
:-)

Mayank

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2005-05-08 13:17 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-01 12:43 [Bluez-devel] SBC Decoder with /dev/dsp Mayank Batra
2005-05-01 12:57 ` Marcel Holtmann
2005-05-01 16:40   ` Marcel Holtmann
2005-05-02  6:43     ` Brad Midgley
2005-05-02  9:56       ` Marcel Holtmann
2005-05-02 15:26         ` Brad Midgley
2005-05-02 18:42           ` Marcel Holtmann
2005-05-03  1:58             ` Brad Midgley
2005-05-03 15:46               ` Marcel Holtmann
2005-05-01 15:21 ` Henryk Plötz
2005-05-03 13:20   ` Mayank Batra
2005-05-03 17:32     ` Henryk Plötz
  -- strict thread matches above, loose matches on Subject: below --
2005-05-03 13:03 Mayank Batra
2005-05-03 13:12 Mayank Batra
2005-05-03 15:36 ` Marcel Holtmann
2005-05-08 13:17 Mayank Batra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.