Intelligent Multimedia System Atmel mega32

Introduction

This project implements a multi-function multimedia system that allows the user to sing with the music video and generate some fancy sound effects.

Intelligent Multimedia System Atmel mega32

In recent decades, multimedia becomes quite popular in our daily life. In fact, multimedia system has existed for a long time. People enjoy the time viewing photos, listening to music, and watching movies. With the development of technology, we are able to create, modify and edit multimedia data. Also, thanks to the emergence of the digital era, we have more tools that help us to achieve these goals. For example, we could store the analog data in digital format to make it more robust and lasting. Besides, we are able to synthesize the data and generate some amazing effects.

Our final project is to design an intelligent multimedia system. This system allows users to use the microphone as the analog input to speak and sing. Besides, since it is not only a multimedia system but an intelligent multimedia system, we have implemented several features that help the users to modify, synthesize, and create a multimedia record. For example, we could adjust the volume of the voice and music. Besides, we could generate the echo of our voice as if we are in a theatre. Furthermore, since we could transform the analog signal into digital format, we are able to manipulate the audio data. In this project, we used several popular mathematical models in the field of Audio Signal Processing that help us to simulate specific sound effects. All the audio data could be recorded in real time by passing to the PC via the RS232 COM Port.

The kernel of the system is controlled by the ATMega32 microcontroller, same as the one we used in the regular lab sections. The voice signal input is generated from the microphone, and the music signal is generated from any music application such as a MP3 player or PC. We passed both of the audio signals through a pre-amplifier to boost its signal strength. Then, we used an analog-to-digital converter chip (ADC0801)  to transform the analog signal into digital data. The digital data can then be propagated to the microcontroller. Besides, we use the RS232 serial port to communicate between the microcontroller and the PC. This design allows us to transfer the music data to the PC from this multimedia system in real time.  In the microcontroller, we could capture both of the voice signal and music signal and mix them to generate special effects. The output signal can then be propagated to a digital-to-analog chip (DAC0808) to transform the digital data to analog signal. Finally, the signal will be passed to the speaker and generate a wonderful melody. In order to provide user with a friendly graphic user interface (GUI), we integrate the technology of JAVA and Visual C++ in Windows programming. User could apply the featured effects to the voice signal via this GUI.

High Level Design

The final project is a good experience for us to integrate all the knowledge that we gained in this course and some other related courses. We chose this topic because we are all interested in multimedia signal processing. Also, we thought that this topic would be a good chance for us to combine our knowledge in various fields. For example, we applied the knowledge that we gained in this course to process the voice and music signal utilizing the optimal capacity of all the components to generate the amazing effects. Also, we could understand more about the analog circuit when we integrated all the hardware components. Furthermore, we had integrated various programming languages such as C, C++ in Windows programming, and Java into our multimedia system. During the process of development, we overcame the challenge of incompatibility between C++ and JAVA. Finally, to process the audio signal, we did some research in the field of Digital Signal Processing and combined some mathematical models to generate proper effects that we applied in this project.

The overall design block of this system is shows as follows. In this project , we used two different channels for our audio signal inputs: one is a microphone and the other is a music application such as MP3 player or PC. Initially both of the signals are in analog format, so we needed two analog-to-digital converters to transform the analog signal into digital format before feeding into the microcontroller. Since there is only one analog-to-digital converter embedded in ATMega32, we used the internal analog-to-digital converter for the voice channel and an external analog-to-digital converter chip (ADC0801) for the music channel. The signal could be manipulated in the microcontroller. The signal will be propagated to the digital-to-analog converter chip (DAC0808) to be transferred into analog format. Finally, the processed signal is passed to a speaker to generate the sound. In this project, we use the GUI in Windows XP as our system control. It provides a user-friendly graphical interface to allow the users to control the system by a mouse click. The mouse click is then turned into a command to the microcontroller via the COM Port.

There were so some minor changes we made in the system architecture while we were working on this project. Some of the changes were made since we encountered some limitation in the hardware. For example, in a common karaoke system, we need at least two channels for one voice input and one music input. However, there is only one internal analog-to-digital converter in ATMega32. If we use it for both voice and music signals alternatively, the sample rate will be reduced to less than half of the original one. This would lower the sound quality. In order to solve this problem, we decided to use an external analog-to-digital converter chip (ADC0801) for the music channel. In this way, the microcontroller can sample both the voice and music signals in 8KHz in maximum concurrently which the produces a higher sound quality. Besides, initially we decided to output the processed signal to the speaker in the same approach that we learned in Lab 2. However, we found that the sound quality was pretty bad since this approach used PWM mode of the microcontroller to generate an approximate signal and hence the accuracy of signal output was lowered. To cope with this problem, we used a digital-to-analog chip (DAC0808) to transform the digital output to an analog output that makes the sound more dulcet. For the choice of user interface, we initially decided to use the buttons on the STK-500 board as the control panel. However, we found that using a PC can provide a much flexible and user-friendly control interface. Hence, we decided to use a GUI running on the PC as the software control panel. All the changes we made help improving the performance of the multimedia system on the whole.

Since all of our team members are ECE MEng students, Cornell University owns all copyrights and potential, patents related to this project. Since the ideas and implementation of our project hardware are solely our own, there should not be any trademark, patent, or copyright infringement issues.

Embedded System Side
In our multimedia system, we used UART of RS232 standard to receive command from PC and send mixed signal output back to PC. Also we used the timers to control the sampling frequency of voice and music signals as well as mixed signal output.

Features/effects supported by the microcontroller firmware

Features/Effects

Description

Implementation Concept

No Effect The multimedia system simply outputs the mixed signals The mixed signal is the combination of the voice signal and the music signal
Frequency Control Users can choose within the range of 1 ~ 8 KHz as the sampling frequency where 8KHz is of best quality The sampling frequency is controlled by the timer interrupt of the microcontroller
Volume Control Users can adjust volume of voice and music signals within the range of 0 ~ 10 scale where 10 is of highest volume The voice and music signals are scaled according to the selected scale before combination
Echo Users can select echo effect within the range of 1 ~ 15 scale where 15 is of most noticeable echo effect The voice output is the combination of 75% of current voice signal and 25% of previous voice signal
Distortion – Patient Voice output sounds like a patient speaking softly The high magnitude of voice input signal is filtered and replaced by the upper bound and lower bound
Distortion – Walki-Talki Voice output sounds like speaking through a walki-talki with distortion The voice output signal is the square of the voice input signal
Distortion – Robot Voice output sounds like a robot voice A high frequency sine wave signal is added to the voice signal
Distortion – Gaussian Noise Voice output consists of additive white Gaussian noise A random signal is added to the voice signal
Distortion – Lower Pitch Voice output sounds like lowering the pitch a bit The voice output signal is generated by averaging 16 previous voice input signals

PC Software

In order to facilitate the communication between a PC and the microcontroller, we make use of the high speed serial port. The console program configures the COM Port to run at a baud rate of 115.2kbps. The program gets the command from the graphical user interface and transmits it to the microcontroller, and at the same time receives the real time digital audio data from the microcontroller. The Java application on top of the console program is to provide graphical user interface for the multimedia system and the useful operations such as displaying the voice waveform, recording the voice in a wave file and sending an email attached with the wave file. The following diagram demonstrates the general data flow between the microcontroller, the console program and the Java application.

The following is the user interface of our program. The left panel is to display the waveform of the audio signal. The right panel is effect control and volume control panel.  All the buttons on the bottom are to control the operations of the multimedia system.

Program / Hardware Design

Software Design – Embedded System Side

 
UART
In our multimedia system, we implemented a Graphical User Interface written in Java running on the PC to control the whole embedded system.  The UART Receive Complete Interrupt is enabled to allow the program jump to the interrupt service routine to receive the command packets.  The received data is then passed to processCommandPacket() to be saved into the command packet buffer. A state machine is implemented in the packet reception. The code is as follows.
 
//UART RX Complete ISR
interrupt [USART_RXC] void uart_receive(void)
begin
    //Process the char received from serial port
    processCommandPacket(UDR);
end
 
//Process command packet received from serial port
void processCommandPacket(unsigned char data)
begin  
    switch (commandState)
    begin
    case CMD_B1:
            //First byte of command
            commandPacket.command = data;
            //Change command state
            commandState = CMD_B2;
            break;
    case CMD_B2:
            //Second byte of command
            commandPacket.command |= (((unsigned int)data)<<8);
            //Change command state
            commandState = LEN_B1;
            break;
    case LEN_B1:
            //First byte of packet length
            commandPacket.dataLen = data;
            //Change command state
            commandState = LEN_B2;
            break;
    case LEN_B2:
            //Second byte of packet length
            commandPacket.dataLen |= (((unsigned int)data)<<8);
            //Change command state
            commandState = DATA_SEC;
            //Disable RX complete interrupt
            UCSRB.7 = 0;
            break;
    end
end
 
There are 7 different commands the PC can send to the microcontroller. They are listed as below.
 
//enum for commands
typedef enum {
    TURN_ON,
    TURN_OFF,
    SET_ECHO,
    SET_MUSIC_VOLUME,
    SET_VOICE_VOLUME,
    SET_SAMPLE_FREQUENCY,
    SET_DISTORTION
} Command;
 
The packet structure for command packet has 4 bytes.  The first 2 bytes are for 16 bits command. The second 2 bytes are for 16 bits payload length of the command packet. The command packet is stored to the variable commandPacket and processed by the checkCommand() function later. The checkCommand() function handles the command packet sent from the PC software. The code is shown as follows.
//enum for command state
typedef enum {
    CMD_B1,
    CMD_B2,
    LEN_B1,
    LEN_B2,
    DATA_SEC
} CommandState;
//Command packet structure
typedef struct CommandPacketTag {
    Command command;
    unsigned int dataLen;
} CommandPacket;
//Check the command and execute it
void checkCommand()
begin
    switch (commandPacket.command)
    begin
            //Turn on the multimedia system
            case TURN_ON:
                    turnOn();
                    commandState=CMD_B1;
                    break;k;
            //turn off the multimedia system
            case TURN_OFF:
                    turnOff();
                    commandState=CMD_B1;
                    break;
            //Set the music volume
            case SET_MUSIC_VOLUME:
                    setMusicVolume();
                    commandState=CMD_B1;
                    break;
            //Set the voice volume
            case SET_VOICE_VOLUME:
                    setVoiceVolume();
                    commandState=CMD_B1;
                    break;
            //Set the sampling frequency
            case SET_SAMPLE_FREQUENCY:                     
                    setSampleFrequency();
                    commandState=CMD_B1;
                    break;
            //Perform the echo effect
            case SET_ECHO:
                    setEcho();
                    commandState=CMD_B1;
                    break;
 
            //Set distortion effect
            case SET_DISTORTION:
                    setDistortion();
                    commandState=CMD_B1;
                    break;
    end  
    //Enable serial communication receive interrupt
    UCSRB.7=1;
End
The sampled audio signal is sent to the PC in the timer interrupt. The code is as follows.
//Send the mixed signal to PC via the serial port
while (!(UCSRA & (1<<5)));
UDR = mixedSignal;
 
Signal Sample Buffer
In the multimedia system, we have designed some special effects for voice processing. Therefore we implemented a sample buffer of size 1500 bytes to store the signal samples and reuse the buffer continuously. The implementation is as follows.
//Number of byte in SRAM used for sample buffer
#define SAMPLE_BUFFER_SIZE 1500
unsigned char sample[SAMPLE_BUFFER_SIZE]; //Sample data array
Internal ADC
Our program used the internal Analog-to-Digital Converter of ATMega32 microcontroller to obtain the voice signal from a microphone via an Op-Amp circuit to amplify the signal strength. The conversion rate is up to 15,000 samples at maximum per second. Our systems sampling rate is 8000 Hz. So the internal ADC suits for our system requirement. The reference voltage is 5V. The Op-Amp circuit has a 2.5V DC-offset. Therefore, for no signal, the digital representation is theoretically 128. But in our tests, we found that the sample data of the voice signal was in fact 120. This is because the DC-offset is not exactly 2.5V and the circuit is imperfect due to interference and impedance.

Intelligent Multimedia System Atmel mega32 Diagram

In the function processSignal(), the following code is to get the voice signal from ADC, store the signal to a sample buffer and then start another conversion.
//Get the voice signal from the ATMega32’s on-chip ADC
voiceSignal = ADCH;
//Store the voice signal in the sample buffer
sample[sampleIndex] = voiceSignal;
//Start another voice ADC conversion
ADMUX = 0b11100000;  
ADCSR.6=1;

Parts List:

Component Quantity Price Remark
ATMega32 1 $8 Lab equipment
Breadboard 1 $0 From trash bin
DAC0808LCN-ND 1 $1.74 Digi-key
ADC0801LCN-ND 1 $9.61 Digi-key
LM358 Operational Amplifier 2 $0 Lab equipment
LM7111 Operational Amplifier 1 $0 Lab equipment
Speaker 1 $0 Sheng-Yi Shih’s
PC 1 $0 Ah Yud Chan’s
Microphone 1 $0 Borrowed from Jimmy Chen

 
For more detail: Intelligent Multimedia System Atmel mega32


About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter
Scroll to Top