00001 #include "asset.h" 00002 #include "mutex.h" 00003 #include "wavecache.h" 00004 00005 #include <string.h> 00006 00007 WaveCacheItem::WaveCacheItem() 00008 : CacheItemBase() 00009 { 00010 } 00011 00012 WaveCacheItem::~WaveCacheItem() 00013 { 00014 } 00015 00016 int WaveCacheItem::get_size() 00017 { 00018 return sizeof(WaveCacheItem) + (path ? strlen(path) : 0); 00019 } 00020 00021 00022 00023 WaveCache::WaveCache() 00024 : CacheBase() 00025 { 00026 } 00027 00028 WaveCache::~WaveCache() 00029 { 00030 } 00031 00032 00033 WaveCacheItem* WaveCache::get_wave(int asset_id, 00034 int channel, 00035 int64_t start, 00036 int64_t end) 00037 { 00038 lock->lock("WaveCache::get_wave"); 00039 int item_number = -1; 00040 WaveCacheItem *result = 0; 00041 00042 result = (WaveCacheItem*)get_item(start); 00043 while(result && result->position == start) 00044 { 00045 if(result->asset_id == asset_id && 00046 result->channel == channel && 00047 result->end == end) 00048 { 00049 result->age = get_age(); 00050 return result; 00051 } 00052 else 00053 result = (WaveCacheItem*)result->next; 00054 } 00055 00056 lock->unlock(); 00057 return 0; 00058 } 00059 00060 void WaveCache::put_wave(Asset *asset, 00061 int channel, 00062 int64_t start, 00063 int64_t end, 00064 double high, 00065 double low) 00066 { 00067 lock->lock("WaveCache::put_wave"); 00068 WaveCacheItem *item = new WaveCacheItem; 00069 item->asset_id = asset->id; 00070 item->path = strdup(asset->path); 00071 item->channel = channel; 00072 item->position = start; 00073 item->end = end; 00074 item->high = high; 00075 item->low = low; 00076 00077 put_item(item); 00078 lock->unlock(); 00079 } 00080 00081 00082 00083 00084 00085
1.5.5