Дмитрий
Feb. 28, 2019, 9:14 p.m.

Opening mp3 files using the audiere library

The audiere library allows you to work with audio files of various formats (wav, mp3, etc.). To work, we need the files audiere.h, audiere.lib, audiere.dll. h-file is included in the program code

  1. #include "audiere.h"

lib-file is linked to .pro

  1. LIBS += audiere.lib

dll we drag behind the program.
In RuNet it is easy to find information on how to play sound with it. But there is absolutely no information on how to get audio data for further processing. Therefore, I will write, especially since it is quite simple.


1 open file

  1. QString name = "D:/qtProg/audioprocessor/test2.mp3";
  2. name.replace("/","\\");
  3. SampleSourcePtr source;
  4. source = OpenSampleSource( name.toLocal8Bit() );
  5. if(!source)
  6. {
  7. ui->statusBar->showMessage("файл не открыт");
  8. return;
  9. }
  10. else
  11. {
  12. ui->statusBar->showMessage(name);
  13. }

2 read audio parameters

  1. int ccount; // число каналов
  2. int samplerate; // частота дискретизации
  3. SampleFormat format; // формат данных
  4.  
  5. source->getFormat(ccount, samplerate, format);
  6. int l = source->getLength(); // число отсчётов одного канала

For typical audio recordings, the number of channels is two, single-channel recordings are quite common, I have not seen others, but it should work on the same principle. Note that the number of samples obtained with getLength() corresponds to one channel. Sampling frequency (if you don't know what it is, check out the Kotelnikov theorem or the Nyquist theorem). Format - determines the number of bits that encode one sample (usually 16).

3 create buffer and suitable storage

  1. int w = 256; // размер временного окна
  2. qint16 buf[w*ccount];
  3.  
  4. QVector<qint16> data; // хранилище данных для одного канала

4 read data

  1. int row = l/w; // число временных фрагментов
  2.  
  3. for(int j = 0; j < row; j++)
  4. {
  5. source->read(w, buf); // считывание фрагмента
  6. for(int i=0; i<w; i++)
  7. {
  8. data.append(buf[i*ccount]);
  9. }
  10. }
  11. source->read(w, buf); // считывание последнего фрагмента
  12. for(int i=0; i < l%w; i++)
  13. {
  14. data.append(buf[i*ccount]);
  15. }

Now the extracted data can be processed...
The text of the program can be downloaded here

By article asked1question(s)

2

Do you like it? Share on social networks!

Evgenii Legotckoi
  • March 1, 2019, 2:27 a.m.
  • (edited)

Добрый день, Дмитрий.

Спасибо за статью. Единственный момент, пожалуйста, поместите статью под кат, то есть отделите большую часть статьи разделителем контента, это одна из кнопок в тулбаре редактора. Она отделяет превью статьи в ленте от остальной части контента.

Ещё раз спасибо.

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html