Реализация встраивания цифрового водяного знака в звуковые файлы методом эхо-сигналов

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование



)==IDOK) .SetWindowText(fd.m_ofn.lpstrFile);

}

//////////////////////////////////////////////////////////////////////////CSoundWatermarkDlg::OnClickedAddWatermark()

{

// check text fields(textFieldsIsEmpty())

{("Specify files first");;

}

// try to open wav file::string pathToWavFile = getPathToWavFile();wavContainer;(!wavContainer.Open(pathToWavFile))

{("Wrong WAV file (should be PCM 16 or 32 bits)");;

}coder;

// get watermark from file::string pathToWatermark = getPathToWatermarkFile();::string watermarkFile;::string line;::ifstream watermarkIfStream(pathToWatermark.c_str());(std::getline(watermarkIfStream,line))+= line;

// check if message will fit containercontainerCapacity = (BITS_PER_SECOND * ((float)wavContainer.Size() / (float)wavContainer.SampleRate())) / 8;(watermarkFile.size() > containerCapacity)

{("Container is too small to inject choosen watermark");;

}

// generate key from watermark filekey("key", Key::STRING);

// inject watermark.SetMessage(&wavContainer, watermarkFile.c_str(), &key);.Save(pathToWavFile);

}

//////////////////////////////////////////////////////////////////////////_msg bool CSoundWatermarkDlg::textFieldsIsEmpty()

{::string pathToWavFile = getPathToWavFile();pathToWatermarkFile[MAX_FNAME_LEN];.GetWindowText(pathToWatermarkFile, MAX_FNAME_LEN);(pathToWavFile.length() == 0 || strlen(pathToWatermarkFile) == 0)

{true;

}false;

}

//////////////////////////////////////////////////////////////////////////::string CSoundWatermarkDlg::getPathToWavFile()

{pathToWavFile[MAX_FNAME_LEN];.GetWindowText(pathToWavFile, MAX_FNAME_LEN);std::string(pathToWavFile);

}

//////////////////////////////////////////////////////////////////////////::string CSoundWatermarkDlg::getPathToWatermarkFile()

{pathToWatermarkFile[MAX_FNAME_LEN];.GetWindowText(pathToWatermarkFile, MAX_FNAME_LEN);std::string(pathToWatermarkFile);

}

А.3 Часть файла echocoder.сpp

////////////////////////////////////////////////////////////////////////////////EchoCoder::SetMessage( WAVContainer* _container, const std::string& _message,

const Key* _key )

{

// Must be a echo key

if ( _key->IsEchoKey() )

{_FrameSize = _container->SampleRate() / BITS_PER_SECOND;(_container);

// Hide message using echo algorithm

LSBSoundCoder::SetMessage(_container, _message);

}

}

////////////////////////////////////////////////////////////////////////////////::string EchoCoder::GetMessage( const WAVContainer* _container, const Key* _key )

{

// Must be a echo key

if ( _key->IsEchoKey() )

{_FrameSize = _container->SampleRate() / BITS_PER_SECOND;(_container);

// Hide message using echo algorithm

return LSBSoundCoder::GetMessage(_container);

}

// Not a echo key

return "";

}

//////////////////////////////////////////////////////////////////////////EchoCoder::CalculateKey(const WAVContainer* _container)

{frameRate = _container->SampleRate();_EchoFirstOffset = frameRate/750;_EchoSecondOffset = frameRate/1500;

}

//////////////////////////////////////////////////////////////////////////EchoCoder::SetBit( bool _bit )

{sizeOfShift = (_bit ? m_EchoFirstOffset : m_EchoSecondOffset);*samplesForShift = new short[sizeOfShift];(samplesForShift, sizeOfShift * sizeof(short));(int i=0; i<m_FrameSize; i++)

{(!JumpToNextSample())

{

// Bit has not been writtenfalse;

}currentSample = GetCurrSample();

// get shifted signalnumberOfShiftedSample = i % sizeOfShift;shiftedSample = samplesForShift[numberOfShiftedSample];

// reduce amplitude (make signal trapezium like)overallReducing = 0.9;coefOfReducing = 1;(i <= 20) {= (float)i/20.0;

}if ((i + 20) > m_FrameSize)

{= ((float)(m_FrameSize - i))/20.0;

}*= overallReducing * coefOfReducing;

// add two signalssampleToSetInt = (int)currentSample + (int)shiftedSample;sampleToSet = currentSample + shiftedSample;(sampleToSetInt > std::numeric_limits::max())

{= std::numeric_limits::max();

}if (sampleToSetInt ::min())

{= std::numeric_limits::min();

}

// set new signal(sampleToSet);[numberOfShiftedSample] = currentSample;

}samplesForShift;

// Bit has been written

return true;

}

////////////////////////////////////////////////////////////////////////////////