Navigation Menu

Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
starkdg committed Mar 24, 2010
1 parent ef91918 commit 75b983b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
24 changes: 9 additions & 15 deletions phash-win32/pHash.sln
Expand Up @@ -5,27 +5,25 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pHash", "pHash.vcproj", "{7
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testaudio", "..\testaudio\testaudio.vcproj", "{5DF982AB-36B1-443E-A9D3-5BE305DC8FFB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testvideo", "..\testvideo\testvideo.vcproj", "{C93F1421-49E9-4712-BF7F-E17C57E3B61E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testmhimage", "..\testmhimage\testmhimage.vcproj", "{7E9970BA-6F47-4777-81EF-8DF507CCECCC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buildmvptree", "..\buildmvptree\buildmvptree.vcproj", "{6AB3E639-AAFB-4611-A175-AD2BFD1B5273}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buildmvptree_mhimage", "..\buildmvptree\buildmvptree.vcproj", "{6AB3E639-AAFB-4611-A175-AD2BFD1B5273}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addmvptree", "..\addmvptree\addmvptree.vcproj", "{95F51657-B5A9-4F52-802D-6CD2A29DD892}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addmvptree_mhimage", "..\addmvptree\addmvptree.vcproj", "{95F51657-B5A9-4F52-802D-6CD2A29DD892}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "querymvptree", "..\querymvptree\querymvptree.vcproj", "{01FFD9AE-0522-43CE-853B-2C914BAAAB24}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "querymvptree_mhimage", "..\querymvptree\querymvptree.vcproj", "{01FFD9AE-0522-43CE-853B-2C914BAAAB24}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buildmvptree2", "..\buildmvptree2\buildmvptree2.vcproj", "{1039AA3D-5394-45EA-BF7F-FDE25C6A31E1}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buildmvptree_dctimage", "..\buildmvptree2\buildmvptree2.vcproj", "{1039AA3D-5394-45EA-BF7F-FDE25C6A31E1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addmvptree2", "..\addmvptree2\addmvptree2.vcproj", "{CB2B26DC-AFD1-499C-A02D-9AE3B23FA233}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addmvptree_dctimage", "..\addmvptree2\addmvptree2.vcproj", "{CB2B26DC-AFD1-499C-A02D-9AE3B23FA233}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "querymvptree2", "..\querymvptree2\querymvptree2.vcproj", "{0B567061-5505-4770-84D3-1667016A8177}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "querymvptree_dctimage", "..\querymvptree2\querymvptree2.vcproj", "{0B567061-5505-4770-84D3-1667016A8177}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buildmvptree3", "..\buildmvptree3\buildmvptree3.vcproj", "{AAE5057F-CEF0-43D2-9270-4CA6DA8D3241}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buildmvptreeaudio", "..\buildmvptree3\buildmvptree3.vcproj", "{AAE5057F-CEF0-43D2-9270-4CA6DA8D3241}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addmvptree3", "..\addmvptree3\addmvptree3.vcproj", "{2F273052-3A61-48DA-8CFF-BDAB0F602D3A}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "addmvptreeaudio", "..\addmvptree3\addmvptree3.vcproj", "{2F273052-3A61-48DA-8CFF-BDAB0F602D3A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "querymvptree3", "..\querymvptree3\querymvptree3.vcproj", "{6AE0A43D-D32F-4F81-B736-A2EF880B4B52}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "querymvptreeaudio", "..\querymvptree3\querymvptree3.vcproj", "{6AE0A43D-D32F-4F81-B736-A2EF880B4B52}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -41,10 +39,6 @@ Global
{5DF982AB-36B1-443E-A9D3-5BE305DC8FFB}.Debug|Win32.Build.0 = Debug|Win32
{5DF982AB-36B1-443E-A9D3-5BE305DC8FFB}.Release|Win32.ActiveCfg = Release|Win32
{5DF982AB-36B1-443E-A9D3-5BE305DC8FFB}.Release|Win32.Build.0 = Release|Win32
{C93F1421-49E9-4712-BF7F-E17C57E3B61E}.Debug|Win32.ActiveCfg = Debug|Win32
{C93F1421-49E9-4712-BF7F-E17C57E3B61E}.Debug|Win32.Build.0 = Debug|Win32
{C93F1421-49E9-4712-BF7F-E17C57E3B61E}.Release|Win32.ActiveCfg = Release|Win32
{C93F1421-49E9-4712-BF7F-E17C57E3B61E}.Release|Win32.Build.0 = Release|Win32
{7E9970BA-6F47-4777-81EF-8DF507CCECCC}.Debug|Win32.ActiveCfg = Debug|Win32
{7E9970BA-6F47-4777-81EF-8DF507CCECCC}.Debug|Win32.Build.0 = Debug|Win32
{7E9970BA-6F47-4777-81EF-8DF507CCECCC}.Release|Win32.ActiveCfg = Release|Win32
Expand Down
Binary file modified phash-win32/pHash.suo
Binary file not shown.
46 changes: 25 additions & 21 deletions phash-win32/src/audiophash.cpp
Expand Up @@ -121,8 +121,7 @@ int ph_count_samples(const char *filename, int sr,int channels){
__declspec(dllexport)
float* ph_readaudio(const char *filename, int sr, int channels, float *sigbuf, int &buflen, const float nbsecs)
{
int cap = 0;

av_log_set_level(AV_LOG_QUIET);
av_register_all();

AVFormatContext *pFormatCtx;
Expand Down Expand Up @@ -196,26 +195,31 @@ float* ph_readaudio(const char *filename, int sr, int channels, float *sigbuf, i
int16_t *out_buf16 = (int16_t*)out_buf;

ReSampleContext *rs_ctx = audio_resample_init(channels, src_channels, sr, src_sr);
int index = 0;
AVPacket packet;
while ((av_read_frame(pFormatCtx, &packet)>=0) && (index < duration))
int64_t index = 0;
AVPacket *packet = (AVPacket*)malloc(sizeof(AVPacket));
av_init_packet(packet);
while ((av_read_frame(pFormatCtx, packet)>=0) && (index < duration))
{

in_buf_used = buf_size;
numbytesread = avcodec_decode_audio2(pCodecCtx,(int16_t*)in_buf,&in_buf_used,packet.data,packet.size);
if (numbytesread <= 0){
continue;
}
int cnt = audio_resample(rs_ctx,(short*)out_buf,(short*)in_buf,(int)(in_buf_used/sizeof(int16_t)));
if (index + cnt > buflen){ /*exceeds capacity of buffer, bail out */
goto readaudio_cleanup;
}
for (int i=0;i<cnt;i++){
buf[index+i] = (float)out_buf16[i]/(float)SHRT_MAX;
while (packet->size > 0){
in_buf_used = buf_size;
numbytesread = avcodec_decode_audio2(pCodecCtx,(int16_t*)in_buf,&in_buf_used,packet->data,packet->size);
if (numbytesread <= 0){
goto readaudio_cleanup;
}
if (in_buf_used > 0){
int cnt = audio_resample(rs_ctx,(short*)out_buf,(short*)in_buf,(int)(in_buf_used/sizeof(int16_t)));
if (index + cnt > buflen){ /*exceeds capacity of buffer, bail out */
goto readaudio_cleanup;
}
for (int i=0;i<cnt;i++){
buf[index+i] = (float)out_buf16[i]/(float)SHRT_MAX;
}
index += cnt;
}
packet->size -= numbytesread;
packet->data += numbytesread;
}

cap += cnt;
index += cnt;
av_destruct_packet_nofree(packet);
}

readaudio_cleanup:
Expand All @@ -224,7 +228,7 @@ float* ph_readaudio(const char *filename, int sr, int channels, float *sigbuf, i
audio_resample_close(rs_ctx);
avcodec_close(pCodecCtx);
av_close_input_file(pFormatCtx);
buflen = cap;
buflen = index;

return buf;
}
Expand Down
4 changes: 2 additions & 2 deletions phash-win32/src/pHash.cpp
Expand Up @@ -844,7 +844,7 @@ MVPRetCode _ph_map_mvpfile(uint8_t filenumber, off_t offset, MVPFile *m,MVPFile
filename = m->filename;
}
if (use_existing){
snprintf(objname, sizeof(objname), "%s%d", filename , filenumber);
snprintf(objname, sizeof(objname), "%s%d", filename+1 , filenumber);
fm_objname = objname;
}
DWORD alloc_size = getregionsize();
Expand Down Expand Up @@ -1239,7 +1239,7 @@ MVPRetCode ph_query_mvptree(MVPFile *m, DP *query, int knearest, float radius, f
filename = m->filename;
}
char fm_objname[32];
snprintf(fm_objname, sizeof(fm_objname), "%s%d", filename ,0);
snprintf(fm_objname, sizeof(fm_objname), "%s%d", filename+1 ,0);

m->file_pos = 0;
HANDLE fmhandle = CreateFileMapping(m->fh,NULL,PAGE_READWRITE,0,0,fm_objname);
Expand Down

0 comments on commit 75b983b

Please sign in to comment.