-
Notifications
You must be signed in to change notification settings - Fork 0
/
flac_read.cpp
94 lines (82 loc) · 2.61 KB
/
flac_read.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
//extern string pfad_uebergabe_mp3;
extern string pfad_uebergabe_flac;
extern string flac_file_info_magic;
extern string flac_tags_content;
void flac_read()
{
//cout<<"flac object file"<<endl;
//cout<<"flac_file_info_magic#"<<flac_file_info_magic<<endl;;
string metaflac_command = "metaflac --show-total-samples --show-sample-rate --show-vendor-tag --show-bps --show-channels --export-tags-to=- '" + pfad_uebergabe_flac + "'" ;
//cout<<metaflac_command<<endl;
char *metaflac_command_char = {(char *) metaflac_command.c_str()};
FILE *pipe;
char str[50000];
pipe = popen (metaflac_command_char, "r" );
if(pipe == NULL)
{
perror("open failed");
pclose(pipe);
exit(0);
}
//metaflac_command = string(str);
//cout<<metaflac_command<<endl;
string flac_metat_data = "";
int i = 0;
string total_samples, sample_rate, vendor_tag, bps, channels, tags;
while(fgets ( str, 49999, pipe ) != NULL)
{
//flac_metat_data = string(str);
//cout<<"flac_metat_data#"<<flac_metat_data<<endl;
//flac_metat_data.append(string(str));
i++ ;
if (i == 1)
{
//cout<<"--show-total-samples#"<<string(str)<<endl;
total_samples=string(str);
}
if (i == 2)
{
//cout<<"--show-sample-rate#"<<string(str)<<endl;
sample_rate=string(str);
}
if (i == 3)
{
//cout<<"--show-vendor-tag#"<<string(str)<<endl;
vendor_tag=string(str);
}
if (i == 4)
{
//cout<<"--show-bps#"<<string(str)<<endl;
bps=string(str);
}
if (i == 5)
{
//cout<<"--show-channels#"<<string(str)<<endl;
channels=string(str);
}
if (i > 5)
{
//cout<<"--export-tags-to#"<<string(str)<<endl;
tags.append(string(str) +"# ");
//tags.append("\n");
}
}
//pipe = popen ("exit", "r" );
pclose(pipe);
double total_samples_int = atof(total_samples.c_str());
//cout<<"total_samples_int#"<<total_samples_int<<endl;
double sample_rate_int = atof(sample_rate.c_str());
//cout<<"sample_rate_int#"<<sample_rate_int<<endl;
double track_sekunden_zeit = total_samples_int / sample_rate_int;
//cout<<"track_sekunden_zeit#"<<track_sekunden_zeit<<endl;
double track_minuten = track_sekunden_zeit / 60;
//cout<<"track_minuten#"<<track_minuten<<endl;
ostringstream strs;
strs << track_minuten;
std::string track_minuten_string = strs.str();
flac_tags_content = tags + "#Track Laenge:" + track_minuten_string + " Minuten \n#Sample Rate:" + total_samples + "#Bits per Sample:" + bps +"#Vendor Tag:" + vendor_tag +"#Channels:" + channels;
}