+ DEBUG_TRACE (DEBUG::Peaks, "DIRECT PEAKS\n");
+
+ off_t map_off = first_peak_byte;
+ off_t read_map_off = map_off & ~(bufsize - 1);
+ off_t map_delta = map_off - read_map_off;
+ size_t map_length = bytes_to_read + map_delta;
+
+ if (_first_run || (_last_scale != samples_per_visual_peak) || (_last_map_off != map_off) || (_last_raw_map_length < bytes_to_read)) {
+ peak_cache.reset (new PeakData[npeaks]);
+ char* addr;
+#ifdef PLATFORM_WINDOWS
+ HANDLE file_handle = (HANDLE) _get_osfhandle(int(sfd));
+ HANDLE map_handle;
+ LPVOID view_handle;
+ bool err_flag;
+
+ map_handle = CreateFileMapping(file_handle, NULL, PAGE_READONLY, 0, 0, NULL);
+ if (map_handle == NULL) {
+ error << string_compose (_("map failed - could not create file mapping for peakfile %1."), _peakpath) << endmsg;
+ return -1;
+ }
+
+ view_handle = MapViewOfFile(map_handle, FILE_MAP_READ, 0, read_map_off, map_length);
+ if (view_handle == NULL) {
+ error << string_compose (_("map failed - could not map peakfile %1."), _peakpath) << endmsg;
+ return -1;
+ }
+
+ addr = (char*) view_handle;
+
+ memcpy ((void*)peak_cache.get(), (void*)(addr + map_delta), bytes_to_read);
+
+ err_flag = UnmapViewOfFile (view_handle);
+ err_flag = CloseHandle(map_handle);
+ if(!err_flag) {
+ error << string_compose (_("unmap failed - could not unmap peakfile %1."), _peakpath) << endmsg;
+ return -1;
+ }
+#else
+ addr = (char*) mmap (0, map_length, PROT_READ, MAP_PRIVATE, sfd, read_map_off);
+ if (addr == MAP_FAILED) {
+ error << string_compose (_("map failed - could not mmap peakfile %1."), _peakpath) << endmsg;
+ return -1;
+ }