Add Sound to your project
Hey gang,
I just received a little·circuit board from All Electronics that records 30 seconds of sound.· Very cute and only $2.· Toy can be easily disassembled and the board is about 1.75" x 2".· Tie the playback pushbutton·switch to a pin on your MCU and you can add·a sinister laugh or other sound to your project.· Stock# SAW-3, allelectronics.com.· Board runs off 2 AAA batteries.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
I just received a little·circuit board from All Electronics that records 30 seconds of sound.· Very cute and only $2.· Toy can be easily disassembled and the board is about 1.75" x 2".· Tie the playback pushbutton·switch to a pin on your MCU and you can add·a sinister laugh or other sound to your project.· Stock# SAW-3, allelectronics.com.· Board runs off 2 AAA batteries.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
Comments
I was looking for cheap way to add a voice to a project.
B-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This post is a work of art. Variations in spelling and grammar are intentional, artistic endeavors that add value to all of mankind.
EEPROM Voice System
24LC512 EEPROMS contain 64k bytes and cost about $3. That makes them ideal for adding some speech to small projects. Here is the set of (DOS) programs and files to do this. This is how the speech was added to the Talking Fish project.
Procedure
Collect the speech sounds in a set of WAV or other files you can edit.
Maximize the level in the file.
Filter the file with a 3500hz low pass function.
Resample the rate to 8khz.
Cut out individual words.
Store them to disk in the SND format, 8 bits, unsigned, 8000 samples/second.
Construct a Sound Control File (filename.scf)
Use TALK to convert the several SND files into one BIN file.
Use HEX (if necessary) to convert the BIN file to a HEX file.
The SCF file is made using a text editor. The first entry is the sample rate. All the rest of the entries (one per line) contain just the base filename of the SND files. With all the files in the same directory, type the following using the SCF filename.
C:>talk filename
This will produce a list on the screen of the filenames, sizes, and space remaining.
The BIN file that is produced contains all of the SND files packed together with a directory in the first locations as follows. Each [noparse][[/noparse]item] is 2 bytes.
[noparse][[/noparse]WS] Word Sound file
[noparse][[/noparse]sample rate]
[noparse][[/noparse]location][noparse][[/noparse]length] (for each sound)
.....
(all of the sound data up to 64k bytes)
Our programmer needs to have data sent to it in HEX file format. The program HEX.EXE can be used to produce one from the BIN file...
C:>hex filename
This produces filename.hex.
The code is in ASM, maybe someone can convert it to SXB. (Just the calling and playing the sound)
;·Freddy the Talking Fish Hack
·device·PIC16F819,pwrte_on,intrc_osc,mclre_on
·org·20h
flag·ds·1
temp·ds·1
data·ds·1
addr·ds·2
low·ds·1
hi·ds·1
size·ds·2
rando·ds·1
rate·ds·1
lbase·ds·1
count·ds·1
var·ds·1
numb·ds·1
loops·ds·1
dela·ds·1
del0·ds·1
del1·ds·1
del2·ds·1
ERROR·=·flag.0
AUX1·=·rb.2··;line-17
AUX2·=·rb.1··;line-18
AUX3·=·rb.0··;line-19
AUX4·=·rb.3··;line-20
SNS1·=·ra.1··;line-9
SNS2·=·ra.2··;line-10
SNS3·=·ra.0··;line-11
SNS4·=·ra.3··;line-12
SNS5·=·ra.5··;line-13 *MCLR
SNS6·=·ra.4··;line-14
MCPCS·=·rb.7··;*Chip Select MCP14010
MCPSCK·=·rb.6··; clock
MCPSI·=·rb.5··; data shift in
SCL·=·ra.6··;clock eeprom
SDA·=·ra.7··;data eeprom
MOUTH·=·AUX1
TAIL·=·AUX2
FACE·=·AUX4
ILL·=·1
BE·=·2
BACK·=·3
GOAHD·=·4
MAKE·=·5
MY·=·6
DAY·=·7
NICE·=·8
BEAVER·=·9
WATS·=·10
UP·=·11
DOC·=·12
MEEP·=·13
URANG·=·14
YO·=·15
SORRY·=·16
BOUT·=·17
THAT·=·18
·org·0
·goto·start
start·bsf·RP0
·movlw·00000001b·;
·movwf·TRISA
·movlw·00000000b·;
·movwf·TRISB
·movlw·0Eh··;analog enables
·movwf·ADCON1··;6=none 0=0-4 0E=0 4=0,1,3
·movlw·70h
·movwf·OSCCON··;8mhz
·movlw·0··;tweek internal os
·movwf·OSCTUNE··;0=center(d) 1F=max 20=min
·bcf·RP0
·movlw·0··;timer 2
·movwf·T2CON··;0=off 4=on
·bsf·SCL
·bsf·SDA
·movlw·2
·movwf·rate
·call·i2stop··;clear i2c lines!
·bcf·AUX1
·bcf·AUX2
·bcf·AUX3
·bcf·AUX4
main·movlw·5
·call·flap
·movlw·100
·call·delay
loop·call·sensit··;look for motion
·call·sensit
·call·switch
·goto·loop
switch·movf·rando,w
·andlw·7
·addwf·PCL
·goto·xbeav
·goto·xmake
·goto·xyo
·goto·xrang
·goto·xback
·goto·xupdoc
·goto·xmeep
·goto·xsory
; photocensor pulls to ground.
; data goes higher on shadows.
sensit·call·litelev··;check photo sensor
·movwf·lbase··;save reference
·movlw·60
·call·delay··;wait a bit
·call·litelev··;read light level
·incf·rando··;count randomly
·subwf·lbase,w··;compare
·sublw·5
·btfsc·c
·goto·sensit··;no increase
·ret
litelev·movlw·0··;read ANA-0
·goto·analog
; make my day
xmake·movlw·goahd
·call·say
·bsf·FACE
·movlw·60
·call·delay
·movlw·make
·call·say
·movlw·my
·call·say
·movlw·day
·call·say
·bcf·FACE
·movlw·3
·call·flap
·ret
xyo·movlw·3
·call·flap
·bsf·FACE
·movlw·80
·call·delay
·movlw·yo
·call·say
·bcf·FACE
·ret
xrang·movlw·3
·call·flap
·bsf·FACE
·movlw·80
·call·delay
·movlw·urang
·call·say
·bcf·FACE
·ret
xbeav·bsf·FACE
·movlw·60
·call·delay
·movlw·NICE
·call·say
·movlw·BEAVER
·call·say
·bcf·FACE
·ret
xmeep·movlw·MEEP
·call·say
·movlw·MEEP
·call·say
·ret
xback·bsf·FACE
·movlw·60
·call·delay
·movlw·ILL
·call·say
·movlw·BE
·call·say
·movlw·BACK
·call·say
·bcf·FACE
·ret
xsory·bsf·FACE
·movlw·60
·call·delay
·movlw·SORRY
·call·say
·movlw·BOUT
·call·say
·movlw·THAT
·call·say
·bcf·FACE
·ret
xupdoc·bsf·FACE
·movlw·60
·call·delay
·movlw·WATS
·call·say
·movlw·UP
·call·say
·movlw·DOC
·call·say
·bcf·FACE
·ret
flap·movwf·count
:2·bsf·TAIL
·call·hsec
·bcf·TAIL
·call·hsec
·decfsz·count
·goto·:2
·ret
hsec·movlw·40
·goto·delay
; SPI write in software
mcxout·movwf·temp
·movlw·11h··;write pot-0
·bsf·MCPSCK
·bcf·MCPCS··;use for /cs signal
·call·:xout
·movf·temp,w
·call·:xout
·bsf·MCPCS
·ret
:xout·movwf·data
·movlw·8
·movwf·count
:x2·rlf·data··;msb first
·btfss·c
·bcf·MCPSI··;tranfer to data pin
·btfsc·c
·bsf·MCPSI
·bcf·MCPSCK··;toggle clock low
·bsf·MCPSCK
·decfsz·count
·goto·:x2
·ret
say·bsf·MOUTH
·call·word
·bcf·MOUTH
·movlw·50
·call·delay
·ret
;·Read sample data out of eeprom
;
;·Sound File Format
;
;·[noparse][[/noparse]MS]··type of data
;·[noparse][[/noparse]rate]··sample rate
;·[noparse][[/noparse]count]··number of entries
;·[noparse][[/noparse]addr][noparse][[/noparse]leng]·absolute address, length
;·(more entries)·rest of entries
;·<...data...>·sound data base
; Finds word pointer in table and play word
; Enter: w = 1-n
word·call·getadr
·call·play
·ret
; get address/size from table
getadr·addlw·-1
·movwf·low··;first (1) is zero offset
·bcf·c
·rlf·low
·bcf·c
·rlf·low··;times 4
·movlw·6··;start of table
·addwf·low
·clrf·hi
·call·rdent··;get location/size
·ret
; read 4 bytes at hi/low into addr/size
rdent·call·i2start··;start condition
·movlw·0A0h
·call·i2wrt··;writing mode
·movf·hi,w
·call·i2wrt··;write high address
·movf·low,w
·call·i2wrt··;write low address
·call·i2start
·movlw·0A1h
·call·i2wrt··;switch to read mode
[noparse]:p[/noparse]2·call·i2rd··;read a byte
·movwf·addr··;low order first
·call·i2ack··;ack for next read
·call·i2rd··;read next byte
·movwf·addr+1··;save high byte
·call·i2ack
·call·i2rd
·movwf·size
·call·i2ack
·call·i2rd
·movwf·size+1
·call·i2nak··;no ack for last byte
·call·i2stop··;always issue stop contition
·ret
; play audio samples at addr for length size
play·call·i2start
·movlw·0A0h
·call·i2wrt
·movf·addr+1,w
·call·i2wrt
·movf·addr,w
·call·i2wrt
·call·i2start
·movlw·0A1h
·call·i2wrt
·goto·[noparse]:p[/noparse]2··;start w/ 1st read
[noparse]:p[/noparse]1·call·i2ack
[noparse]:p[/noparse]2·call·i2rd
·call·mcxout
;;·movf·rate,w
;;·call·timer
·decfsz·size
·goto·[noparse]:p[/noparse]1
·decfsz·size+1
·goto·[noparse]:p[/noparse]1··;do ack
·call·i2nak··;last one
·call·i2stop
·ret
timer·movwf·dela
:x2·nop
·nop
·nop
·decfsz·dela
·goto·:x2
·ret
;
End Vocal Operations
;
I2C operations for EEPROMS
;
; create valid start condition
; run clock as output and data as open collector
i2start·bsf·RP0
·bcf·SCL··;clock is active output
·bcf·RP0
·bcf·SCL··;clock low for safety
·nop
·bsf·RP0
·bsf·SDA··;preset data high
·bcf·RP0
·nop
·bsf·SCL··;arm for start - but...
·bcf·SDA··;keep data latch low
·bsf·RP0
·bcf·SDA··;pull data low
·bcf·RP0
·nop
·bcf·SCL··;return clock low
·bcf·ERROR
·ret
; create stop condition
i2stop·bcf·SCL··;just in case...
·bcf·SDA··;always!
·bsf·RP0
·bcf·SDA··;data line to output mode
·bcf·RP0
·nop
·bsf·SCL··;arm for op
·nop
·bsf·RP0
·bsf·SDA··;creat stop condition
·bcf·RP0
·nop
·bcf·SCL··;clear the clock.
·ret
; write byte of data, check for ACK on each.
i2wrt·movwf·temp
·movlw·8
·movwf·count
:nxt·rlf·temp··;get next bit
·bcf·SDA··;always!
·bsf·RP0··;use tristate bit
·btfsc·c
·bsf·SDA··;flaot (high)
·btfss·c
·bcf·SDA··;or grab (low)
·bcf·RP0
·nop
·bsf·SCL··;600 ns clock high
·nop
·nop
·bcf·SCL
·decfsz·count
·goto·:nxt
·bsf·RP0
·bsf·SDA··;flaod data line
·bcf·RP0
·nop
·nop
·bsf·SCL··;read the ACK
·nop
·btfss·SDA
·goto·:ack
·bcf·SCL
·bsf·ERROR
·ret··;signal no ack
:ack·bcf·SCL
·ret
; read byte from i2c
; assume clock is low
i2rd·movlw·8
·movwf·count
·bsf·RP0
·bsf·SDA··;set data to
·bcf·RP0··;input (float) mode
:nxt·bsf·SCL··;start clock
·bcf·c
·btfsc·SDA
·bsf·c
·bcf·SCL
·rlf·temp··;high order first
·decfsz·count
·goto·:nxt
·movf·temp,w
·ret
; send ACK to eeprom
i2ack·bcf·SDA··;always!
·bsf·RP0
·bcf·SDA··;pull data low
·bcf·RP0
·nop
·bsf·SCL
·nop
·nop
·nop
·nop
·bcf·SCL
·ret
; send NAK to eeprom
i2nak·bsf·RP0
·bsf·SDA··;pull data low
·bcf·RP0
·nop
·nop
·bsf·SCL
·nop
·nop
·nop
·nop
·bcf·SCL
·ret
;
End I2C Code
; read analog channel specified in 'w'
; (works in pic16F819)
analog·andlw·3
·movwf·temp
·bcf·c
·rlf·temp
·rlf·temp
·rlf·temp
·movf·temp,w
·iorlw·5··;turn on and start
·movwf·ADCON0
:a2·btfsc·ADCON0,2·;wait for done
·goto·:a2
·movf·ADRESH,w·;get high 8 bits
·ret
; qubic delay routine
delay·movwf·del2
:x2·movwf·del1
:x1·movwf·del0
:x0·decfsz·del0
·goto·:x0
·decfsz·del1
·goto·:x1
·decfsz·del2
·goto·:x2
·ret
·end
Have Fun.
Glenn