Assignment 5 - Music Player
Assignment 5 - Music Player
92025/5/
222024/1/til 92025/5/
Detaljer
Introduction
In this assignment, you will create a music-player in C or C++ that can play songs using the PCSPK device
(simple audio device). For this assignment to work, you also need PIT implemented to make correct timings
between notes.
💡 If you did not implement PIT, you can still implement this, without timings and that will give full score.
Learning outcomes
Interacting with hardware devices
Deliverables:
1. Working sound from PCSPK using PIT
Assignment Files
assignment_files.zip (https://prod-files-secure.s3.us-west-2.amazonaws.com/ed4d188b-1830-428e-a82c-
4fc22f71a8ee/d3b55f45-9d69-4473-86c2-f075adcaa12c/assignment_files.zip)
#include "song/song.h"
#include "pit.h"
#include "common.h"
#include "libc/stdio.h"
void enable_speaker() {
// Pseudocode for enable_speaker:
// 1. Read the current state from the PC speaker control port.
// 2. The control register bits are usually defined as follows:
// - Bit 0 (Speaker gate): Controls whether the speaker is on or off.
// - Bit 1 (Speaker data): Determines if data is being sent to the speaker.
// 3. Set both Bit 0 and Bit 1 to enable the speaker.
// - Use bitwise OR operation to set these bits without altering others.
}
void disable_speaker() {
// Pseudocode for disable_speaker:
// 1. Read the current state from the PC speaker control port.
// 2. Clear both Bit 0 and Bit 1 to disable the speaker.
// - Use bitwise AND with the complement of 3 (0b11) to clear these bits.
}
void stop_sound() {
// Pseudocode for stop_sound:
// 1. Read the current state from the PC speaker control port.
// 2. Clear the bit that enables speaker data to stop the sound.
// - Use bitwise AND with the complement of the bit responsible for enabling the speaker data.
}
Code in main.cpp
// Outside of main
SongPlayer* create_song_player() {
auto* player = new SongPlayer();
player->play_song = play_song_impl;
return player;
}
while(true){
for(uint32_t i =0; i < n_songs; i++){
printf("Playing Song...\\n");
player->play_song(songs[i]);
printf("Finished playing the song.\\n");
}
};
Submission
Complete the "Music Player" section for the final report
When done with coding, you can submit a pull request to the UiAIKT github repository to verify that your
submission works (no conflicts and all checks passed)