From: Kenneth Johansson <kenneth@southpole.se>
To: patch@alsa-project.org
Cc: alsa-devel@alsa-project.org
Subject: [PATCH] Sample generation on big endian platforms was broken.
Date: Fri, 03 Jul 2009 16:19:31 +0200 [thread overview]
Message-ID: <1246630771.7922.25.camel@localhost.localdomain> (raw)
Has not worked since commit 3d1fa924906996463ac33cba5b5143f762d913cf
Signed-off-by: Kenneth Johansson <kenneth@southpole.se>
---
test/pcm.c | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/test/pcm.c b/test/pcm.c
index ee27422..9b8a923 100644
--- a/test/pcm.c
+++ b/test/pcm.c
@@ -34,14 +34,11 @@ static void generate_sine(const
snd_pcm_channel_area_t *areas,
static double max_phase = 2. * M_PI;
double phase = *_phase;
double step = max_phase*freq/(double)rate;
- double res;
+ int res;
unsigned char *samples[channels], *tmp;
int steps[channels];
- unsigned int chn, byte;
- union {
- int i;
- unsigned char c[4];
- } ires;
+ unsigned int chn;
+
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
int bps = snd_pcm_format_width(format) / 8; /* bytes per sample */
@@ -62,11 +59,18 @@ static void generate_sine(const
snd_pcm_channel_area_t *areas,
/* fill the channel areas */
while (count-- > 0) {
res = sin(phase) * maxval;
- ires.i = res;
- tmp = ires.c;
for (chn = 0; chn < channels; chn++) {
- for (byte = 0; byte < (unsigned int)bps; byte++)
- *(samples[chn] + byte) = tmp[byte];
+ /* Generate data in native endian format */
+ switch(bps){
+ case 1:
+ *(samples[chn]) = res;
+ break;
+ case 2:
+ *(short*)(samples[chn]) = res;
+ break;
+ case 4:
+ *(int*)(samples[chn]) = res;
+ }
samples[chn] += steps[chn];
}
phase += step;
--
1.6.1.GIT
next reply other threads:[~2009-07-03 14:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-03 14:19 Kenneth Johansson [this message]
2009-07-03 14:39 ` [PATCH] Sample generation on big endian platforms was broken Takashi Iwai
2009-07-03 14:51 ` Kenneth Johansson
2009-07-03 15:00 ` Takashi Iwai
2009-07-03 15:11 ` Kenneth Johansson
2009-07-03 15:28 ` Takashi Iwai
2009-07-03 15:41 ` Takashi Iwai
2009-07-03 17:04 ` Kenneth Johansson
2009-07-03 19:36 ` Takashi Iwai
2009-07-03 15:58 ` Kenneth Johansson
2009-07-03 16:59 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1246630771.7922.25.camel@localhost.localdomain \
--to=kenneth@southpole.se \
--cc=alsa-devel@alsa-project.org \
--cc=patch@alsa-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.