// Name: Sean Smith // Class and Section: CS 54, Section // Date: April 17, 2007 // Purpose: Implementation of the different bands for the templated Radio #include "bands.h" /* default AM constructor */ AM::AM() { setFrequency(1337); setStereo(true); } /* initialization AM constructor */ AM::AM(int newFrequency, bool newStereo) { /* set default values first in case passed in values are FUBAR */ setFrequency(1337); setStereo(true); /* now set the passed in values; they will change if they're valid */ setFrequency(newFrequency); setStereo(newStereo); } /* returns whether the broadcast is in stereo */ bool AM::inStereo() const { return stereo; } /* returns the frequency the broadcast is on */ int AM::getFrequency() const { return frequency; } /* prints information about the broadcast */ void AM::print() const { cout << "Frequency: " << frequency << " kHz" << endl; cout << "Stereo : "; if (stereo) cout << "yes" << endl; else cout << "no" << endl; } /* changes the frequency of the broadcast */ void AM::setFrequency(int newFrequency) { if (newFrequency >= 530 && newFrequency <= 1710) frequency = newFrequency; } /* changes whether the broadcast is in stereo */ void AM::setStereo(bool newStereo) { /* this trick will force the stereo value to strictly 0 or 1 */ if (newStereo) stereo = true; else stereo = false; } /* default FM constructor */ FM::FM() { setFrequency(89.7); setStereo(true); } /* initialization FM constructor */ FM::FM(double newFrequency, bool newStereo) { /* set default values first in case passed in values are FUBAR */ setFrequency(89.7); setStereo(true); /* now set the passed in values; they will change if they're valid */ setFrequency(newFrequency); setStereo(newStereo); } /* returns whether the broadcast is in stereo */ bool FM::inStereo() const { return stereo; } /* returns the frequency the broadcast is on */ double FM::getFrequency() const { return frequency; } /* prints information about the broadcast */ void FM::print() const { cout << "Frequency: " << frequency << " MHz" << endl; cout << "Stereo : "; if (stereo) cout << "yes" << endl; else cout << "no" << endl; } /* changes the frequency of the broadcast */ void FM::setFrequency(double newFrequency) { if (newFrequency > 87.7 && newFrequency < 108.0) frequency = newFrequency; } /* changes whether the broadcast is in stereo */ void FM::setStereo(bool newStereo) { /* this trick will force the stereo value to strictly 0 or 1 */ if (newStereo) stereo = true; else stereo = false; } /* default IceCast constructor */ IceCast::IceCast() { setURL("http://web.umr.edu/~kmnr/raudio/kmnr.m3u"); setBitRate(49152); } /* initialization IceCast constructor */ IceCast::IceCast(string newURL, int newBitRate) { /* set default values first in case passed in values are FUBAR */ setURL("http://web.umr.edu/~kmnr/raudio/kmnr.m3u"); setBitRate(49152); /* now set the passed in values; they will change if they're valid */ setURL(newURL); setBitRate(newBitRate); } /* returns the sampling rate of the IceCast */ int IceCast::getBitRate() const { return bitRate; } /* returns the URL of the IceCast */ string IceCast::getURL() const { return url; } /* prints information about the broadcast */ void IceCast::print() const { cout << "Streaming From: " << url << endl << "Sampling Rate : " << bitRate << " bps" << endl; } /* sets the sampling rate of the IceCast */ void IceCast::setBitRate(int newBitRate) { bool valid = false; unsigned short i; /* see if the new bit rate is valid */ for (i = 0; i < NUM_BITRATES; i++) if (newBitRate == validBitRates[i]) { valid = true; break; } /* if so, set it! */ if (valid) bitRate = newBitRate; } /* sets the URL of the IceCast */ void IceCast::setURL(string newURL) { url = newURL; }