In: Computer Science
The fidelity of an audio clip is defined by a number of parameters, including the number of channels (1 or 2), the resolution (8, 16 or 24 bits per sample), and the sampling rate (22050, 44100, or 88200 samples per second).
(a) Write a definition for an audioClip class that contains:
(b) [04 points] Write a new method called isStudioQuality that will return true or false, depending upon whether the audio clip stored has the maximum possible quality (i.e., two channels, 24-bit resolution, and a sample rate of 88200 samples per second).
(c) [03 points] Write a new method called dataSize that accepts the duration that an audio clip lasts in seconds (as an integer), and returns the number of bytes that this audio clip would occupy on disk or in memory. The formula for calculating number of bytes, ?, where is ? duration (in seconds), ? is channels, ? is resolution (in bits), and ? is sample rate, is: ? = ? × ? × (?/ 8) × ?
C#
(a).
class audioClip
{
private: int channels;
int resolution;
int sampleRate;
public: audioClip()
{
channels = 1;
resolution = 8;
sampleRate = 22050;
}
int getChannels()
{
return channels;
}
bool setChannels(int newChannels)
{
if(newChannels==1 || newChannels==2)
{
channels = newChannels;
return true;
}
return false;
}
int getResolution()
{
return resolution;
}
bool setResolution(int newResolution)
{
if(newResolution==8 || newResolution==16 || newResolution==24)
{
resolution = newResolution;
return true;
}
return false;
}
int getSampleRate()
{
return sampleRate;
}
bool setSampleRate(int newSampleRate)
{
if(newSampleRate==22050 || newSampleRate==44100 || newSampleRate==88200)
{
resolution = newSampleRate;
return true;
}
return false;
}
};
(b)
public: bool isStudioQuality()
{
if(channels==2 && resolution==24 && sampleRate==88200)
return true;
return false;
}
(c)
public:
int dataSize(int duration)
{
return duration*channels*sampleRate*(resolution/8);
}