[go: up one dir, main page]

0% found this document useful (0 votes)
16 views2 pages

Assignment 5 - Music Player

The assignment requires creating a music player in C or C++ that utilizes the PCSPK device for sound playback, with the option to implement the Programmable Interval Timer (PIT) for accurate timing. Key deliverables include enabling sound from the PCSPK and implementing functions to play and stop sound, as well as managing song playback. Students must submit their completed code and a final report section on the music player, followed by a pull request to the UiAIKT GitHub repository for verification.

Uploaded by

drhammad2257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Assignment 5 - Music Player

The assignment requires creating a music player in C or C++ that utilizes the PCSPK device for sound playback, with the option to implement the Programmable Interval Timer (PIT) for accurate timing. Key deliverables include enabling sound from the PCSPK and implementing functions to play and stop sound, as well as managing song playback. Students must submit their completed code and a final report section on the music player, followed by a pull request to the UiAIKT GitHub repository for verification.

Uploaded by

drhammad2257
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 5 - Music Player

92025/‫‏‬5/‫‏‬

Legg til kommentar

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)

Pseudocode for playing sound using PCSPK device


SongPlayer.cpp

#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 play_sound(uint32_t frequency) {


// Pseudocode for play_sound:
// 1. Check if the frequency is 0. If so, exit the function as this indicates no sound.
// 2. Calculate the divisor for setting the PIT (Programmable Interval Timer) frequency.
// - The PIT frequency is a base value, typically 1.193182 MHz.
// - The divisor is PIT frequency divided by the desired sound frequency.
// 3. Configure the PIT to the desired frequency:
// - Send control word to PIT control port to set binary counting, mode 3, and access mode (low/high byte).
// - Split the calculated divisor into low and high bytes.
// - Send the low byte followed by the high byte to the PIT channel 2 port.
// 4. Enable the speaker (by setting the appropriate bits) to start sound generation.
}

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.
}

void play_song_impl(Song *song) {


// Pseudocode for play_song_impl:
// 1. Enable the speaker before starting the song.
// 2. Loop through each note in the song's notes array:
// a. For each note, display its details such as frequency and duration.
// b. Call play_sound with the note's frequency.
// c. Delay execution for the duration of the note (this can be implemented with a sleep function).
// d. Call stop_sound to end the note.
// 3. Disable the speaker after all notes have been played.
}

void play_song(Song *song) {


// Pseudocode for play_song:
// 1. Call play_song_impl with the given song.
// - This function handles the entire process of playing each note in the song.
}

Code in main.cpp
// Outside of main
SongPlayer* create_song_player() {
auto* player = new SongPlayer();
player->play_song = play_song_impl;
return player;
}

// How to play music


Song* songs[] = {
new Song({music_1, sizeof(music_1) / sizeof(Note)})
};
uint32_t n_songs = sizeof(songs) / sizeof(Song*);

SongPlayer* player = create_song_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)

You might also like