Forum: Projekte & Code 1-bit audio example program for Atmega


von Michael H. (mah)


Angehängte Dateien:

Lesenswert?

Anbei ein Beispiel für die Verwendung von 1bit-Audio mit einem Atmega32.

- Michael

README:

This is an example avr-gcc C implementation of 1-bit audio for AVR 
controllers.

My hardware is an ATMega32 with a 12Mhz crystal, fuses 0xCE and 0x99.

The encoded sound file is stored in program flash (PROGMEM). When you 
press the key the sound file will be played. The LED is turned on during 
playback.

For the encoding method, see Roman Black's website at 
http://www.romanblack.com/picsound.htm .

To encode a sound file:

- run BTc Sound Encoder 2.0 on the sound file
- export as 'PIC MikroC .C file'
- run perl btc2avr.pl <MikroC.C >sound.h  to convert to avr-gcc syntax
- compile sample program.

The perl script btc2avr.pl defines the  'char sound[] PROGMEM = {....}' 
array and extracts several parameters as #defines which can be used for 
conditional compilation:

#define BTC_ONE_BIT 0
#define BTC_ONEPOINTFIVE_BIT 1
#define BTC_UNKNOWN 2

// values for current sound file:
#define SOUND_BITS 111646
#define SOUND_BYTES 13955
#define SOUND_ALGORITHM BTc16
#define SOUND_ALGORITHM_NAME "BTc16"
#define SOUND_ENCODING BTC_ONEPOINTFIVE_BIT
#define SOUND_RATE 22050

Depending on these sound file #defines, the appropriate decoder is 
compiled and timer0 setup to generate the proper playback clock.

For the low-pass filter hardware setup, see the comments in the PIC 
MicroC file.
At the capacitor the audio comes out at roughly 3V peak-to-peak. You 
might need an amplifier to drive a speaker.

Key debouncing code is by Peter Danegger.
See Beitrag "Universelle Tastenabfrage" .

Updates might appear on 
http://mah.priv.at/cgi-bin/viewvc.cgi/1bit-audio/?root=CVS .

--

Since I use Eclipse+AVR plugin, no Makefile. Instead, here's the build 
log:

**** Build of configuration Debug for project 1bit-audio ****

make all
Building file: ../main.c
Invoking: AVR Compiler
avr-gcc -I/usr/local/AVRMacPack-20090319/avr-3/include -Wall -g2 -gstabs 
-Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields 
-mmcu=atmega32 -DF_CPU=12000000UL -MMD -MP -MF"main.d" -MT"main.d" -c 
-o"main.o" "../main.c"
../main.c:27:2: warning: #warning choosing prescaler=8 CS=CS01
Finished building: ../main.c

Building target: 1bit-audio.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,1bit-audio.map -mmcu=atmega32 -o"1bit-audio.elf" 
./main.o
Finished building target: 1bit-audio.elf

Invoking: AVR Create Extended Listing
avr-objdump -h -S 1bit-audio.elf  >"1bit-audio.lss"
Finished building: 1bit-audio.lss

Create Flash image (ihex format)
avr-objcopy -R .eeprom -O ihex 1bit-audio.elf  "1bit-audio.hex"
Finished building: 1bit-audio.hex

Invoking: Print Size
avr-size --format=avr --mcu=atmega32 1bit-audio.elf
AVR Memory Usage
----------------
Device: atmega32

Program:   14658 bytes (44.7% Full)
(.text + .data + .bootloader)

Data:         12 bytes (0.6% Full)
(.data + .bss + .noinit)


Finished building: sizedummy


Michael Haberler April 2009

von Uwe S. (de0508)


Angehängte Dateien:

Lesenswert?

Hallo Michael,

ich habe das Programm nur in der Frequenz 14745000 und dem Port, nun 
PORTB über
1
#define
, angepasst.

Hardware
PB0: Taster nach Masse, und 10k mit PullUp an +5V
PB1: K-LED-A mit 470 Ohm nach +5V
PB2, PB3: Soundausgabe an je 27k||680k

Ein kleiner LM386N-1 mit 5V dient mir als Verstärker für einen 8 Ohm 
Visaton Breitbandlautsprecher.

Ergänzung

1) ich habe "BTc Sound Encoder 3.0 Software" zum kodieren einer 22050 
bit/s WAVE-Datei verwendet.

http://www.romanblack.com/picsound.htm

Leider habe ich es noch nicht geschafft die weiteren CODECS (1.6, 1.7) 
aus zu probieren.

2) Anbei noch eine Makefile und main.c für das Projekt.

von Fragezeichen (Gast)


Lesenswert?

Was ist der Unterschied gegenüber der naiven Ausgabe der Samples direkt 
per "Fast-PWM-DAC"?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.